问题描述
staticvoidMain(string[]args){inti=3;OleDbConnectionthisconnection=newOleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Datasource=qiqi.mdb");OleDbDataAdapterthisadapter=newOleDbDataAdapter();thisadapter.SelectCommand=newOleDbCommand("select*from[#Class]",thisconnection);OleDbCommandBuilderthisbuilder=newOleDbCommandBuilder(thisadapter);DataSetthisdataset=newDataSet();thisadapter.Fill(thisdataset,"class");Console.Write("{0}->{1}",thisdataset.Tables["class"].Rows[i]["ClassName"],name);thisdataset.Tables["class"].Rows[i]["ClassName"]="妈妈,我爱你";thisadapter.UpdateCommand=thisbuilder.GetUpdateCommand();thisadapter.Update(thisdataset,"class");thisconnection.Close();Console.ReadKey();}
解决方案
解决方案二:
staticvoidMain(string[]args){inti=3;OleDbConnectionthisconnection=newOleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Datasource=qiqi.mdb");OleDbDataAdapterthisadapter=newOleDbDataAdapter("select*from[#Class]",thisconnection);OleDbCommandBuilderthisbuilder=newOleDbCommandBuilder(thisadapter);DataSetthisdataset=newDataSet();thisadapter.Fill(thisdataset,"class");Console.Write("{0}->{1}",thisdataset.Tables["class"].Rows[i]["ClassName"],name);thisdataset.Tables["class"].Rows[i]["ClassName"]="妈妈,我爱你";thisadapter.UpdateCommand=thisbuilder.GetUpdateCommand();thisconnection.Close();Console.ReadKey();}不好意思打错了。最后提示我UPdate语句语法错误。可是书上都这么说的。。。
解决方案三:
使用了OleDbCommandBuilder,直接Update就可以了。OleDbCommandBuilder自动生成UpdateSQL