Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从.NET的SQL数据库中动态删除_C#_Sql_.net_Dynamic_Sql Delete - Fatal编程技术网

C# 从.NET的SQL数据库中动态删除

C# 从.NET的SQL数据库中动态删除,c#,sql,.net,dynamic,sql-delete,C#,Sql,.net,Dynamic,Sql Delete,我有一个SQL数据库,它存储通过文本框输入的值。然后通过网格框在我的输出屏幕上显示该数据库的值。有没有办法让用户选择要删除哪一列?类似于网格框中值附近的删除按钮 如果不是,如何在SQL中删除变量列号。比如,如果用户想要删除第10行。如何将其合并到SQL delete命令中 它是否应该包含“top”命令?如果是,怎么做 protected void Button3_Click(object sender, EventArgs e) { SqlConnection sc = new SqlC

我有一个SQL数据库,它存储通过文本框输入的值。然后通过网格框在我的输出屏幕上显示该数据库的值。有没有办法让用户选择要删除哪一列?类似于网格框中值附近的删除按钮

如果不是,如何在SQL中删除变量列号。比如,如果用户想要删除第10行。如何将其合并到SQL delete命令中

它是否应该包含“top”命令?如果是,怎么做

protected void Button3_Click(object sender, EventArgs e)
{
    SqlConnection sc = new SqlConnection();

    sc.ConnectionString = ("Data Source=abc; Initial Catalog=VisualStudioTest; User ID=USER; Password=PASS");
    sc.Open();

    SqlCommand com = new SqlCommand();
    com.Connection = sc;
    com.CommandText = ("delete from notes");//initially I've kept this to delete everything.

    com.ExecuteNonQuery();

    sc.Close();
    Response.Redirect(Request.RawUrl);
}
标记:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     DataSourceID="SqlDataSource1" 
     OnSelectedIndexChanged="GridView1_SelectedIndexChanged1">
    <Columns>
        <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:VisualStudioTestConnectionString3 %>" 
     SelectCommand="SELECT [Notes] FROM [Notes]" 
     OnSelecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>

我假设您的目标是删除一行

我想到的最简单的方法是添加一个标识字段作为表的键,将新列添加到
GridView
DataKeyNames
列表中,然后将一个参数添加到
SqlDataSource
中的
DeleteQuery

delete from notes where identityCol = @identityCol;

最后一步是将delete控件添加到
Gridview

从不根据记录的索引删除记录。。。如果要删除特定记录,请使用其主键进行删除。这是SQL Server,是哪个版本?请添加相应的标签!