中间过程不写了,直接记录下代码给个记忆:
List<string> mysqls = new List<string>();
string sqlstring;
DataBase db = new DataBase();
for (int i = 0; i < employyAttRecordDataGridView.Rows.Count; i++)
{
sqlstring="update employyAttRecord set ";
sqlstring += "worktime=" + employyAttRecordDataGridView.Rows[i].Cells["WorkTimeCol"].Value.ToString();
sqlstring += ",otm=" + employyAttRecordDataGridView.Rows[i].Cells["OTmCol"].Value.ToString();
if (employyAttRecordDataGridView.Rows[i].Cells["Att1Col"].Value.ToString() != string.Empty) sqlstring += ",Att1='" + employyAttRecordDataGridView.Rows[i].Cells["Att1Col"].Value.ToString()+"'";
if (employyAttRecordDataGridView.Rows[i].Cells["Att2Col"].Value.ToString() != string.Empty) sqlstring += ",Att2='" + employyAttRecordDataGridView.Rows[i].Cells["Att2Col"].Value.ToString() + "'";
if (employyAttRecordDataGridView.Rows[i].Cells["Att3Col"].Value.ToString() != string.Empty) sqlstring += ",Att3='" + employyAttRecordDataGridView.Rows[i].Cells["Att3Col"].Value.ToString() + "'";
if (employyAttRecordDataGridView.Rows[i].Cells["Att4Col"].Value.ToString() != string.Empty) sqlstring += ",Att4='" + employyAttRecordDataGridView.Rows[i].Cells["Att4Col"].Value.ToString() + "'";
if (employyAttRecordDataGridView.Rows[i].Cells["Att5Col"].Value.ToString() != string.Empty) sqlstring += ",Att5='" + employyAttRecordDataGridView.Rows[i].Cells["Att5Col"].Value.ToString() + "'";
if (employyAttRecordDataGridView.Rows[i].Cells["Att6Col"].Value.ToString() != string.Empty) sqlstring += ",Att6='" + employyAttRecordDataGridView.Rows[i].Cells["Att6Col"].Value.ToString() + "'";
sqlstring += " where recordid=" + employyAttRecordDataGridView.Rows[i].Cells["RecordID"].Value.ToString();
mysqls.Add(sqlstring);
}
db.ExecDataBySqls(mysqls);