问题描述
我使用如下的语句更新数据表时,数值、时间、逻辑类型的可以更新,但是字符类型的不能更新,不知道为什么?希望高手指点,真是郁闷。System.Data.OleDb.OleDbCommandBuildermyCommandBuilder;myDataAdapter=newOleDbDataAdapter(ShowSql,conn);datagridview1.EndEdit();//生成Delete/Update/Insert操作的CommandmyCommandBuilder=newSystem.Data.OleDb.OleDbCommandBuilder(myDataAdapter);//myCommandBuilder.GetDeleteCommand=myDataAdapter.DeleteCommand=myCommandBuilder.GetDeleteCommand();myDataAdapter.UpdateCommand=myCommandBuilder.GetUpdateCommand();myDataAdapter.InsertCommand=myCommandBuilder.GetInsertCommand();try{//保存到数据库myDataAdapter.Update(myDataSet,tablename);myDataSet.AcceptChanges();//myDataAdapter.Update(myDataSet.Tables[tablename]);}catch(Exceptionerr){myCommandBuilder.Dispose();MessageBox.Show(err.Message,"错误信息",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Exclamation);return;}
解决方案
解决方案二:
myDataAdapter.DeleteCommand=myCommandBuilder.GetDeleteCommand();myDataAdapter.UpdateCommand=myCommandBuilder.GetUpdateCommand();myDataAdapter.InsertCommand=myCommandBuilder.GetInsertCommand();//这些好像没有必要,是不是字段长度不够?好好看一下MSDN,里面有详细的介绍关于这一块,
解决方案三:
等看
解决方案四:
dingxiaxian
解决方案五:
看看报什么错。
解决方案六:
myCommandBuilder=newSystem.Data.OleDb.OleDbCommandBuilder(myDataAdapter);//myCommandBuilder.GetDeleteCommand=myDataAdapter.DeleteCommand=myCommandBuilder.GetDeleteCommand();myDataAdapter.UpdateCommand=myCommandBuilder.GetUpdateCommand();myDataAdapter.InsertCommand=myCommandBuilder.GetInsertCommand();声明了第一句,后面的都是默认的
解决方案七:
我知道原因了,就是在数据提取时,我使用了rtrim即selectrtrim(f1)asf1,rtrim(f2)asf2fromtable去掉rtrim保存就正确,这是为什么。如果不用rtrim,在datagridview中就有...,很难看,不知道怎么去掉