C#如何实现datatable 中的数据灌入到Oracle中自己创建的表中(我已经将Excel中的数据导入到了datatable中

2024-10-28 19:03:13
有2个网友回答
网友(1):

加入提交命令!! 你没有提交!

for(int i=0;i {
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
OracleTransaction mytran = conn.BeginTransaction();
OracleCommand cmd3 = new OracleCommand("insert into JBGLB(" + " 员工号 , 姓名, 部门名, 月份, 日期 " + ") values(" + " " + dtbl.Rows[i]["员工号"] + ",'" + dtbl.Rows[i]["姓名"].ToString() + "','" + dtbl.Rows[i]["部门名"].ToString() + "'," + dtbl.Rows[i]["月份"] + "," + dtbl.Rows[i]["日期"] + " " + " )", conn3);
cmd3.ExecuteNonQuery();
mytran.Commit();
conn3.Close();
cmd3.Dispose();
}

网友(2):

代码这样很麻烦
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
for(int i=0;i {
OracleCommand cmd3 = new OracleCommand("insert into JBGLB(" + " 员工号 , 姓名, 部门名, 月份, 日期 " + ") values(" + " " + dtbl.Rows[i]["员工号"] + ",'" + dtbl.Rows[i]["姓名"].ToString() + "','" + dtbl.Rows[i]["部门名"].ToString() + "'," + dtbl.Rows[i]["月份"] + "," + dtbl.Rows[i]["日期"] + " " + " )", conn3);
cmd3.ExecuteNonQuery();
}
conn3.Close();