I create a excel using ole db provider, like below
string connString = "Data Source=" + fullPath + "; Provider=Microsoft.Jet.OLEDB.4.0; Extended Properties=Excel 8.0;";
OleDbConnection myConn=new OleDbConnection(connString);
OleDbCommand myCommand=new OleDbCommand();
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment string )";
// connect an excel file, if this file doesn't exist, it will be created
myConn.Open();
// create a workbook in this file
myCommand.ExecuteNonQuery();
The problem is when import more than 255 characters into Excel, error occurs:
OLEDBException: The field is too small to accept the amount of data you attempted to add.....
This is because string in Excel has the limitation of 255 characters. To work around this, change the datatype to memo
myCommand.CommandText = "CREATE TABLE Report (msisdn string, comment memo)";
No comments:
Post a Comment