首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

SqlDataAdapter.Update方法更新不了库表中的数据?该如何处理

2012-04-16 
SqlDataAdapter.Update方法更新不了库表中的数据??急急急 ?想用SqlDataAdapter.Update方法修改dataGridVie

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);


……

[解决办法]
建议自己写数据库更新 我是这样做的。。。

热点排行