【发布时间】:2011-05-09 09:50:35
【问题描述】:
我刚刚从 Visual Studio 2005 收到这条消息,当我单击删除命令时,我使用配置网格的界面添加到我的 gridview:
数据不支持删除 源“事务SqlDataSource” 除非指定了 DeleteCommand。
如何激活它?我希望我的用户能够在单击“删除”按钮时删除一行。
我已经将 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? =)
-
指定它必须执行的存储过程(删除时)?
-
@J. Steen 你的意思是删除查询?
-
@Mythje 我不明白,我是怎么做到的?
-
不,我的意思是 DeleteCommand,正如 Crypth 在下面回答的那样。 msdn.microsoft.com/en-us/library/…
标签: c# .net asp.net visual-studio