如何更新DataGridView
以便它也会影响数据库中的更改?我正在尝试的代码是:
foreach (DataGridViewRow myDgrow in dataGridView2.Rows) {
myCmd = "Update Details set ProjectName='"
+ myDgrow.Cells["ProjectName"].Value
+ "', Description = '"
+ myDgrow.Cells["Description"].Value
+ "', DateStarted='"
+ myDgrow.Cells["DateStarted"].Value
+ "',TeamSize='"
+ myDgrow.Cells["TeamSize"].Value
+ "',Manager='"
+ myDgrow.Cells["Manager"].Value
+ "'";
myCmd = "Update Details set Description = '"
+ myDgrow.Cells["Description"].Value
+ "', DateStarted='"
+ myDgrow.Cells["DateStarted"].Value
+ "',TeamSize='"
+ myDgrow.Cells["TeamSize"].Value
+ "',Manager='"
+ myDgrow.Cells["Manager"].Value
+ "' where ProjectName='"
+ myDgrow.Cells["ProjectName"].Value
+ "'";
cmd.Parameters.AddWithValue("@projectName1", myDgrow.Cells["ProjectName"].Value);
cmd.Parameters.AddWithValue("@Description1", myDgrow.Cells["Description"].Value);
cmd.Parameters.AddWithValue("@DateStarted1", myDgrow.Cells["DateStarted"].Value);
cmd.Parameters.AddWithValue("@TeamSize1", myDgrow.Cells["TeamSize"].Value);
cmd.Parameters.AddWithValue("@Manager1", myDgrow.Cells["Manager"].Value);
cmd.CommandText = myCmd;
dataGridView2.Update();
//cmd.Parameters.Clear();
cmd.ExecuteNonQuery();
myCmd = string.Empty;
}