日期:2014-05-18  浏览次数:20902 次

SqlDataAdapter.Update方法更新不了库表中的数据??急急急

? 想用SqlDataAdapter.Update方法修改dataGridView控件返回的库表,dataAdapter.Update(dataSet, "tScore");
这条语句总是出错,似乎只是修改了DataSet中的数据,而没能修改库表中的数据?

?private void btnUpdate_Click(object sender, EventArgs e)
? {
? try
? {
? SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter);
? dataAdapter.Update(dataSet, "tScore");
? }
? catch (Exception ex) ?
? {
? MessageBox.Show("ex.Message", "数据库操作出错",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
? }
? finally
? {
? MessageBox.Show("OVER!");
? }

? }

------解决方案--------------------
你看看报错信息是什么啊,看看Exception ex中ex的内容,里面会告诉你出什么错了,比如主键重复,字段不允许为空等
------解决方案--------------------
调试自己看,你直接messabox了,当然不显示了
------解决方案--------------------
MessageBox.Show("ex.Message", "数据库操作出错",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
=>
MessageBox.Show(ex.Message, "数据库操作出错",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
------解决方案--------------------
探讨
引用:
MessageBox.Show("ex.Message", "数据库操作出错",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
=>
MessageBox.Show(ex.Message, "数据库操作出错",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);


……

------解决方案--------------------
建议自己写数据库更新 我是这样做的。。。