sqlbulkcopy:数据被截断

时间:2012-08-06 11:44:35

标签: c# sql-server sqlbulkcopy

当我从csv插入数据时;描述列数据被截断,长度为255。

描述varchar(max),nvarchar(max),text等的数据类型。

我的代码

string CsvConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +filelocation +"; Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";             
using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
{
    OleDbCommand command = new OleDbCommand("Select * FROM ["+filename+"]", connection);
    connection.Open();               
    using (DbDataReader dr = command.ExecuteReader())
    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
    {                       
        bulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping("description", "description")); 
        bulkCopy.DestinationTableName = "Table1";               
        bulkCopy.WriteToServer(dr);                        
    }       
}

VS2010,C# SQL2008 R2 10.50 Express

请建议是否有其他方法可以将数据从CSV插入SQL Server

0 个答案:

没有答案