C#如何实现datatable 中的数据灌入到Oracle中自己创建的表中(我已经将Excel中的数据导入到了datatable中
for(inti=0;i<dtbl.Rows.Count;i++){OracleConnectionconn3=newOracleConnection("datasour...
for(int i=0;i<dtbl.Rows.Count;i++)
{
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
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);
conn3.Close();
cmd3.Dispose();
}
编译能通过 但运行后表中始终无任何数据 展开
{
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
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);
conn3.Close();
cmd3.Dispose();
}
编译能通过 但运行后表中始终无任何数据 展开
展开全部
加入提交命令!! 你没有提交!
for(int i=0;i<dtbl.Rows.Count;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();
}
for(int i=0;i<dtbl.Rows.Count;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();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码这样很麻烦
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
for(int i=0;i<dtbl.Rows.Count;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();
OracleConnection conn3 = new OracleConnection("data source=myoracle1;user Id=scott;password=123456");
conn3.Open();
for(int i=0;i<dtbl.Rows.Count;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();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询