如何在C#中的datagridview中从MYSQL删除数据SELECTED(CHECKED)?

我的代码:

 string CONFIG = "server=localhost;userid=root;password=admin;database=program";
 MySqlConnection cone = new MySqlConnection(CONFIG);

 MySqlCommand query2 = new MySqlCommand();
 query2.Connection = cone;
 query2.CommandText = "DELETE FROM TABLE WHERE ID = @ID";
 // I believe the key from this problem stay in line below//
 query2.Parameters.AddWithValue("@ID", gridMovie.SelectedRows);

  cone.Open();
  query2.ExecuteNonQuery();
  cone.Close();

最佳答案

gridview的SelectedRow属性给出整个行。因此,您需要提供列值(在这种情况下,它是ID)-

query2.Parameters.AddWithValue("@ID", gridMovie.SelectedRow
                 .Cells[indexofIDcolumn].Value)

关于c# - C#DatagridVIew删除SQL日期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20199158/

10-10 13:00