Excel OleConnection Insert Statements

How would insert a row into an excel document. This is what I have. String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file_path + ";Extended Properties=Excel 8.0;"; DataTable dt = new DataTable(); DataSet ds = new DataSet(); OleDbConnection conn = new OleDbConnection(connString); OleDbCommand cmd = new OleDbCommand(str_insert, conn); cmd.CommandTimeout = 3600; try { cmd.Connection = conn; DataSet active_ds = new DataSet(); cmd.CommandText = str_insert; if (conn.State != ConnectionState.Open) conn.Open(); foreach (DataRow dr in details_dt.Rows) { cmd.CommandText = "INSERT INTO [DETAILS$](Ipt, Ipt Ownr, Order, Order Delivery Date, Assembly, Description, Component, User, Name, Change Code, Reason Code, Value New, Value Old," + "Date, Time, Auth Doc, Plant, Mfg Source, Order Type, Model, Effy) " + "VALUES(" + dr.ItemArray[0].ToString() + "," + dr.ItemArray[1].ToString() + "," + dr.ItemArray[2].ToString() + "," + dr.ItemArray[3].ToString() + "," + dr.ItemArray[4].ToString() + "," + dr.ItemArray[5].ToString() + "," + dr.ItemArray[6].ToString() + "," + dr.ItemArray[7].ToString() + "," + dr.ItemArray[8].ToString() + "," + dr.ItemArray[9].ToString() + "," + dr.ItemArray[10].ToString() + "," + dr.ItemArray[11].ToString() + "," + dr.ItemArray[12].ToString() + "," + dr.ItemArray[13].ToString() + "," + dr.ItemArray[14].ToString() + "," + dr.ItemArray[15].ToString() + "," + dr.ItemArray[16].ToString() + "," + dr.ItemArray[17].ToString() + "," + dr.ItemArray[18].ToString() + "," + dr.ItemArray[19].ToString() + "," + dr.ItemArray[20].ToString() + "," + dr.ItemArray[21].ToString() + ")"; cmd.ExecuteNonQuery(); }
What version of Excel? Are you getting errors? Are you open the connection fine?

以上就是Excel OleConnection Insert Statements的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏