【发布时间】:2014-09-20 07:52:48
【问题描述】:
C# Windows 窗体
我有一个从 dataGridView 中删除选定行的按钮。 我还希望该按钮能够检索选定行的“orderre”列值,因此我可以在从 sql 表中删除订单的查询中使用它。
我的代码如下所示:
dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
//SQL connection
SqlConnection con = new SqlConnection(@"Data Source=" + globalvariables.hosttxt + "," + globalvariables.porttxt + "\\SQLEXPRESS;Database=ha;Persist Security Info=false; UID='" + globalvariables.user + "' ; PWD='" + globalvariables.psw + "'");
SqlCommand command = con.CreateCommand();
//SQL QUERY
command.CommandText = "DELETE FROM bestillinger WHERE ordrenr = @ordre";
command.Parameters.AddWithValue("@ordre",dataGridView1.SelectedRows[0].Cells["ordre"].Value.ToString())
con.Open();
var ordre = command.ExecuteScalar();
con.Close();
但它不起作用!没有记录被删除
【问题讨论】:
标签: c# sql winforms datagridview get