//數據庫連接
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();
檢查下主鍵是否重復,不許為空的字段是否指定值,等等。