DatagridView批量修改数据
SqlCommandBuilder builder = new SqlCommandBuilder(data);
data.Update(ds, "mydt");
怎么用?
现在我一个DatagridView的数据源是DataTable。
但是我要大批量的修改。然后我就考虑到了SqlCommandBuilder 。
但是好像行不通?
[解决办法]
private void UpdateDataGridView(DataGridView dataGridView1)
{
string sql = "select *** from TABLE where *** ";
try
{
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection("***"))
{
conn.Open();
using (SqlDataAdapter adp = new SqlDataAdapter(sql, conn))
{
using (SqlCommandBuilder scb = new SqlCommandBuilder(adp))
{
adp.Fill(dt);
adp.Update(dt);
dataGridView1.DataSource = dt;
dataGridView1.Refresh();
}
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), "Information");
}
}