DataGridView内数据更改后数据库更新的问题
要实现的功能是如果DataGridView内有改动,则在点击某个按钮后更新数据库。代码是这样的:namespace CarScheduleForCosco
{
class ButtonUpdate
{
public void ButtonClick(string tableName, int ColumnNo,DataGridView UpdateData)
{
datasource buttonUpdate = new datasource();
OleDbConnection updatecon = buttonUpdate.datacon();
OleDbDataAdapter updateAdapter = new OleDbDataAdapter();
updateAdapter.SelectCommand = buttonUpdate.datacom("select * from'" + tableName + "'", updatecon);
OleDbCommandBuilder updateBuilder = new OleDbCommandBuilder(updateAdapter);
DataSet updateDataSet=new DataSet();
try
{
updatecon.Open();
updateAdapter.Fill(updateDataSet,"'"+tableName+"'");
DataTable UpdateTable = updateDataSet.Tables["'" + tableName + "'"];
int RowNo=UpdateData.RowCount;
for (int i = 0; i < RowNo; i++)
{
DataRow UpdateRow=UpdateData.Rows[i];
for (int j = 0; j < ColumnNo; j++)$
{
UpdateRow["'" + UpdateData.Columns[j].HeaderText+"'"] = UpdateData[j,i].Value; //问题,内容不匹配
}
}
updateAdapter.Update(updateDataSet, "'" + tableName + "'");
}
catch
{
MessageBox.Show("“保存”过程出错");
}
finally
{
updatecon.Close();
}
}
}
}
红色那个部分总是说没有办法转换,我该怎么办呢?