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