110,533
社区成员
发帖
与我相关
我的任务
分享
//早说不就得了,非要转一个大弯?
public void DGUpdate(String SQLString, DataGridView dataGridview,string connectionString)
{
dataGridview.EndEdit();
SQLDataAdapter Adapter = new SQLDataAdapter();
DataTable table = (DataTable)dataGridview.DataSource;
using (SQLConnection connection = new SQLConnection(connectionString))
{
Adapter.SelectCommand = new SQLCommand(SQLString, connection);
SQLCommandBuilder builder = new SQLCommandBuilder(Adapter);
Adapter.UpdateCommand = builder.GetUpdateCommand();
try
{
Adapter.Update(table);
table.AcceptChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
//调用
string sql="select * from 你之前select的表"
DGUpdate(sql, DataGridView1,connectionString)