我刚刚从 Visual Studio 2005 收到此消息,当时我使用用于配置网格的界面单击添加到我的 gridview 的删除命令:
Deleting is not supported by data source 'transactionsSqlDataSource' unless DeleteCommand is specified.
我怎样才能激活它?我希望我的用户在单击“删除”按钮时能够删除一行。
我已经将 SQLDataSource 的属性 DeleteCommandType 更改为 StoredProcedure。 我还需要做什么?
更新
这就是我所做的,但是我遗漏了一些东西,我无法编译:
这是我在 .cs 中所做的:
public string DeleteCommand { get; set; }
我该如何解决这个问题,它说 get 缺少正文。我不习惯 ASP.NET。你能帮我修复这部分代码吗?
这是我在 .aspx 中所做的:
<asp:SqlDataSource ID="transactionsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:membershipsDBConnectionString %>"
SelectCommand="SELECT [brukerId], [kjoptekvoten], [pengeneutbetalt], [fyringsolje], [biltype], [kjoptid] FROM [Informasjon]" DeleteCommandType="StoredProcedure"
DeleteCommand="DELETE FROM [Informasjon] WHERE fyringsolje='Kull: 2,42 kg';">
</asp:SqlDataSource>
数据源的配置是否正确?如果你看到删除命令没有像上面那样使用参数,请不要担心,这只是一个作业(我只需要查询通过)。
更新 2 我一直在尝试,但我无法修复它。我真的是 ASP.NET 的新手,我不是很熟悉所有的术语。这里究竟发生了什么?我如何知道我的存储过程的名称?:
CS:
public string DeleteCommand { get { return DeleteCommand; } set { DeleteCommand = "";}
Aspx:
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:membershipsDBConnectionString %>"
DeleteCommandType="StoredProcedure" SelectCommand="SELECT [id], [kjoptekvoten], [pengeneutbetalt], [fyringsolje], [biltype], [kjoptid] FROM [Informasjon]"
DeleteCommand="StoredProcedureName">
</asp:SqlDataSource>
当我单击“删除”时,需要从表 Informasjon 中删除该行
最佳答案
DeleteCommand="<your stored proc>"
在您的 SqlDataSource 中需要连同您想要的任何参数,例如:
<DeleteParameters>
<asp:Parameter Name="myParameter" Type="Int32" />
</DeleteParameters>
需要在SqlDatasource标签中添加。
关于c# - 我的数据源不支持删除?我怎样才能激活它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5935200/