I am using sqlbulkcopy class to read excel in a table
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + targetFileName + ";Extended Properties=Excel 12.0;";
//OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + targetFileName + @";Extended Properties=""Excel 8.0;IMEX=1;ImportMixedTypes=Text;HDR=YES;""");
OleDbConnection con = new OleDbConnection(connStr);
OleDbCommand myCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", con);
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(System.Configuration.ConfigurationManager.ConnectionStrings["CrossMediaConnectionString"].ToString()))
try
{
{
#region SqlBulkCopy
bulkCopy.DestinationTableName = "tbl_TempProductData";
bulkCopy.ColumnMappings.Add("product_code", "ProductCode");
bulkCopy.ColumnMappings.Add("product_name", "ProductName");
bulkCopy.ColumnMappings.Add("category_relation_id", "RelatedCategoryId");
bulkCopy.ColumnMappings.Add("short_description", "ProductDescription");
con.Open();
bulkCopy.WriteToServer(myCommand.ExecuteReader());
}
}
but ProductDescription reads only 255 characters even for table tbl_TempProductData I have set length to max