问题描述
- 添加一组数据时,提示insert into 语法错误
-
//数据库连接 string connstr = "Provider=Microsoft.Jet.OleDb.4.0;"; connstr += @"Data Source=D:Merger201503016caohuanGEARCNC.mdb";//创建连接对象 OleDbConnection tempconn = new OleDbConnection(connstr); tempconn.Open(); string str="select * from WorkPieceData"; OleDbCommand acommand = new OleDbCommand(str , tempconn); OleDbDataAdapter WorkPieceDataDA = new OleDbDataAdapter(); DataSet ds = new DataSet(); WorkPieceDataDA.SelectCommand = acommand; WorkPieceDataDA.Fill(ds, "WorkPieceData"); tempconn.Close(); //新建一行 DataRow dr = ds.Tables["WorkPieceData"].NewRow(); //为各字段赋值 dr["齿数"] = ChiShu.Text; dr["法面模数"] = BiaoZhunMoShu.Text; ds.Tables["WorkPieceData"].Rows.Add(dr);//将新行添加到表中 OleDbCommandBuilder builder = new OleDbCommandBuilder(WorkPieceDataDA); tempconn.Open(); WorkPieceDataDA.Update(ds,"WorkPieceData"); tempconn.Close();
解决方案
检查下主键是否重复,不许为空的字段是否指定值,等等。
解决方案二:
主键你打开access,表中画一个钥匙的字段就是。
解决方案三:
我已经解决了,谢谢,我只是在ACCESS数据库中的字段改为了“必需”,我也不知道为什么
解决方案四:
肯定是表中的字段约束了的原因。
时间: 2024-11-02 10:55:09