private void button2_Click(object sender, EventArgs e)
{
this.dataGridView1.EndEdit();
SqlConnection conn = new SqlConnection("server=.;integrated security=SSPI;database=test"); SqlCommand cmd = new SqlCommand("select * from a", conn);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
da.SelectCommand = cmd;
da.Fill(ds, "a");
SqlCommandBuilder cb = new SqlCommandBuilder();
try
{
SqlCommandBuilder SCB = new SqlCommandBuilder(da);
da.Update(dt);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
错误信息是什么?
没有错误,就是存不进去
SqlCommand cmd = new SqlCommand("select * from a", conn); 你这个里面是查询语句啊,怎么会修改数据呢.
那该怎么改呀?
@巴索罗缪库玛:
select * from a把这个改成update 表名 set 字段='aaaa'
@荒野的呼唤: 你是说“aaa”是具体的数么?我想直接在datagridview控件的表格中随意改都能存进去,不是写程序写进去固定的一个数,比如表中是3,我改成4数据库里就存成4,改成5数据库里就存5.能实现么?