在线等。。。 从Excel中读取数据到DataTable中循环插入到Oracle中耗时长的问题 怎么解决?????????

smputao 2012-05-09 12:41:39
如题,现有一个excel数据文档,想把excel里面的数据都导入到oracle数据库中

1.先从Excel中读取数据到DataTable中。
2.循环DataTable,插入到Oracle中。

但是有的excel最多的有6W多行数据循环插入太慢 有什么好办法呢?
...全文
236 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xudlQQ123 2012-05-15
  • 打赏
  • 举报
回复
我做过和你类似的一个上传项目,同时导入8张表.导入到Oracle数据中.其中的复杂度要比你这个要复杂的多.数据量也很大.但是用的时间却很少.在net写一个公共事物方法.逐条生成一条SQL语句,放到ArraList中,进行批量插入.如果你要想要的话,我这里有源码,我可以发给你.挺复杂的.
QQ:740303282
你可以加我,我明天拿U盘拷给你.
anzhiqiang_touzi 2012-05-15
  • 打赏
  • 举报
回复

create table #table (ID char(1),Name char(100))


INSERT INTO #table
select 1 as ID,'Nam1' as Name where not exists(select NULL from #table where ID=1)

INSERT INTO #table
select 2 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=2)

INSERT INTO #table
select 3 as ID,'Nam3' as Name where not exists(select NULL from #table where ID=3)

INSERT INTO #table
select 4 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=4)

INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)


INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)
INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)
INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)
INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)
INSERT INTO #table
select 5 as ID,'Nam2' as Name where not exists(select NULL from #table where ID=5)


select * from #table
drop table #table


我用sqlerver导入是这么做的
你改成Oracle的就行了
smputao 2012-05-15
  • 打赏
  • 举报
回复
不加验证也很慢 因为是给客户用 所以只要代码导入的方法
现在用的是以下这种方法导入的:
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
OleDbConnection ExcelConn = new OleDbConnection(strCon);
try
{
string strCom = string.Format(sql);
ExcelConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, ExcelConn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "[" + tableName + "$]");
ExcelConn.Close();
ExcelConn.Dispose();
return ds;
}
catch
{
ExcelConn.Close();
ExcelConn.Dispose();
return null;
}
这种效率低
zhangdaowu5 2012-05-09
  • 打赏
  • 举报
回复
这样肯定会比较慢啊,既要导入数据又要进行验证,光导入就得花费时间何况还要对每行进行数据验证。
smputao 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

试试每1000条提交一次,这个数字可能根据数据量或者服务器自己有一个调整。
[/Quote]
问题是我每一条数据以后都要加判断验证了
xuan.ye 2012-05-09
  • 打赏
  • 举报
回复
试试每1000条提交一次,这个数字可能根据数据量或者服务器自己有一个调整。

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧