小弟现有一个从别的部门导出的文本文件(CSV),有1.2GB ,需要把它导入到SQLSERVER中(别人从ORACLE中导出),直接使用SQL的导入工具将直接死机(2GB)内存。
听别人说需要编一个程序,采用读入数据块的方法才能导入数据块。具体怎么实现呢?请各位大哥帮忙。
听别人说需要编一个程序,采用读入数据块的方法才能导入数据块。具体怎么实现呢?请各位大哥帮忙。
解决方案 »
- C#用什么语言可以实现VB的Frameset功能
- 如何判断一IP在一网段间?(C#)
- 正则表达式(很简单)
- 在删除GAC目录中的程序集时报"Assembly'...'could not be uninstalled because it is required by other applications."
- 求个思路,批量文本转换器是怎么写出来的?
- 为什么带有中文的cs文件添加到vs2005项目中全部变成乱码?
- 请教一个IIS问题
- VS.NET 2005 如何添加 Directx 的COM 组件啊
- 怎样得到windows中使用的是大字体还是小字体
- 这么奇怪的问题!?
- 关于C#的DataSet的问题。。。
- 求关于输入认证的代码C# 50分虽然不多 略表心意
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
string file = of.FileName;
using (SqlConnection con = new SqlConnection("server=.;database=test2;uid=sa;pwd=sa"))
{
con.Open();
byte[] ptr;
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[1024];
int count = fs.Read(buffer, 0, 1024);
//insert some data ,in that the image field will not be null
using (SqlCommand cmd=con.CreateCommand ())
{
cmd.CommandText = "insert into blob (id,file2) values ('1',@file2)";
SqlParameter sfile= cmd.Parameters.Add("@file2",SqlDbType.Image );
sfile.Value = buffer;
cmd.ExecuteNonQuery();
}
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select TEXTPTR(file2) from blob where id='1'";
ptr = (byte[])cmd.ExecuteScalar();
}
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "updatetext blob.file2 @ptr @offset null @data";
SqlParameter sptr = cmd.Parameters.Add("@ptr", SqlDbType.Binary, 16);
SqlParameter soffset = cmd.Parameters.Add("@offset", SqlDbType.Int);
SqlParameter sdata = cmd.Parameters.Add("@data", SqlDbType.Image ); sptr.Value = ptr;
soffset.Value = 0;
int index = 0;
while (true)
{
count = fs.Read(buffer, 0, 1024 );
if (count==0)
{
break;
}
if (count<1024)
{
int i = 0;
}
sdata.Value = buffer;
sdata.Size = count;
cmd.ExecuteNonQuery();
index += count;
soffset.Value = index;
}
}
}
}
By Sébastien Lorion
http://www.codeproject.com/cs/database/CsvReader.asp