怎么将txt文件中的数据导入到数据库中,数据量较大

zh6335901 2011-11-23 12:27:55
大家有没什么好的方法,从文件中读一行,然后往数据库插入一行的速度太慢了。。
...全文
107 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
铜臂阿铁木 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sandy945 的回复:]

http://topic.csdn.net/u/20111120/13/ea5dbcbd-286d-48c1-bcbd-7ca6ac643f62.html
[/Quote]

freemangood 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sandy945 的回复:]
http://topic.csdn.net/u/20111120/13/ea5dbcbd-286d-48c1-bcbd-7ca6ac643f62.html
[/Quote]

+++ 这个方法很经典!
wenyegood 2011-11-23
  • 打赏
  • 举报
回复
2楼这样办法也可行
[Quote=引用 2 楼 sdl2005lyx 的回复:]

C# code

public static List<String[]> ReadTxt(string filePathName)
{
List<String[]> ls = new List<String[]>();
StreamReader fileReader=new StreamReader(file……
[/Quote]
sdl2005lyx 2011-11-23
  • 打赏
  • 举报
回复

public static List<String[]> ReadTxt(string filePathName)
{
List<String[]> ls = new List<String[]>();
StreamReader fileReader=new StreamReader(filePathName);
string strLine="";
while (strLine != null)
{
strLine = fileReader.ReadLine();
if (strLine != null && strLine.Length>0)
{
ls.Add(strLine.Split(','));
//Debug.WriteLine(strLine);
}
}
fileReader.Close();
return ls;
}


先用说明函数一次性读出txt的数据,然后转换到DataTable中(也可边读txt,边转换),
最后用用SqlDataAdapter一次性写入数据库。。。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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