用Excel做DB,連接字符串如下:ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TEST.xls;Extended Properties='Excel 8.0;HDR=YES;'";用OleDbDataAdapter對(duì)Excel進(jìn)行數(shù)據(jù)插入,代碼如下:OleDbConnection oleConn = new OleDbConnection(ConnectionString);oleConn.Open();OleDbCommand oleCmd = new OleDbCommand("select * from " + tableName, oleConn);OleDbDataAdapter da = new OleDbDataAdapter(oleCmd);ds1 = new DataSet();da.Fill(ds1, "[sheet1$]");ds1.Tables[tableName].PrimaryKey = new DataColumn[] { ds1.Tables[tableName].Columns[0] };DataRow row = ds1.Tables["[sheet1$]"].NewRow();row[0] = 1;row[1] = "Hello";OleDbCommandBuilder myCommandBuilder = new OleDbCommandBuilder(da); da.InsertCommand = myCommandBuilder.GetInsertCommand();da.Update(ds1,tableName); //提示“Syntax error in INSERT INTO statement” 請(qǐng)教大俠,問(wèn)題到底出在哪里,郁悶了許久,google了也沒(méi)找出問(wèn)題。ps:也設(shè)了主鍵,應(yīng)該不是主鍵問(wèn)題
- 1 回答
- 0 關(guān)注
- 544 瀏覽
添加回答
舉報(bào)
0/150
提交
取消