如何更新DataGridView
以便它也會影響數據庫中的更改? 我正努力的代碼是: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;
}
call dataGridView2.Update();在cmd.ExecuteNonQuery()之後;並重試 – Sumeshk
[DataGridView更新數據庫]的可能重複(http://stackoverflow.com/questions/18459416/datagridview-updating-database) – Bridge