0

When i inserted data from csv; description column data truncated with length 255.

datatype for description varchar(max), nvarchar(max), text, etc tried.

my code

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

Please suggest if there are another methods for inserting data from CSV to SQL Server

twoflower
  • 6,788
  • 2
  • 33
  • 44
Jkrish
  • 159
  • 2
  • 16
  • possible duplicate of [Excel cell-values are truncated by OLEDB-provider](http://stackoverflow.com/questions/898513/excel-cell-values-are-truncated-by-oledb-provider) – Alex K. Aug 06 '12 at 11:54
  • schema.ini meathod works. thanks guys. Reference : [link](http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx) – Jkrish Aug 07 '12 at 11:53

0 Answers0