c# - 我的数据源不支持删除?我怎样才能激活它?

标签 c# .net asp.net visual-studio

我刚刚从 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 中删除该行 Screenshot of GridView

最佳答案

DeleteCommand="<your stored proc>"

在您的 SqlDataSource 中需要连同您想要的任何参数,例如:

<DeleteParameters>
  <asp:Parameter Name="myParameter" Type="Int32" />
</DeleteParameters>

需要在SqlDatasource标签中添加。

关于c# - 我的数据源不支持删除?我怎样才能激活它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5935200/

相关文章:

asp.net - Azure Web App 数据库在哪里?

c# - 静态字段初始化在 C# 中如何工作?

c# - string.Format 异常输入字符串的格式不正确

c# - 是否有开箱即用的方法来反序列化 Json.Net 中的抽象类?

c# - 在 ASP.NET 页面中加载 iframe

c# - ASP.NET C# 从代码隐藏中设置 OnSelectedIndexChanged

c# - 对标记为 ASCII 的 EXIF 属性使用 UTF8 解码是否安全?

c# - 如何通过不同的类将文本发送到文本框?

c# - ASP.NET Core 从 Querystring 反序列化 IEnumerable<KeyValuePair<string, string>>>

c# - 如何从 C# 中的类型(只有没有版本或文化或 publickeyToken 的程序集名称)中获取程序集名称(非限定名称)