程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c#-添加一組數據時,提示insert into 語法錯誤

c#-添加一組數據時,提示insert into 語法錯誤

編輯:編程綜合問答
添加一組數據時,提示insert into 語法錯誤
        //數據庫連接
        string connstr = "Provider=Microsoft.Jet.OleDb.4.0;";
        connstr += @"Data Source=D:\Merger201503016caohuan\GEARCNC.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();

最佳回答:


檢查下主鍵是否重復,不許為空的字段是否指定值,等等。

caohuan95568
caohuan95568
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved