Reputation: 39
I used OleDb for importing Excel file which is having 2000 columns. So by using this piece of code i can able to have only 255 columns in my DataTable. I want some other way or if possible this way to get 2000 columns to my DataTable.
DataTable dtExcelRecords = new DataTable();
using (OleDbConnection con = new OleDbConnection(connectionString))
{
con.Open();
DataTable dtSheet = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
List<string> listSheet = new List<string>();
foreach (DataRow drSheet in dtSheet.Rows)
{
if (drSheet["TABLE_NAME"].ToString().Contains("$"))
{
listSheet.Add(drSheet["TABLE_NAME"].ToString());
}
}
string workSheetName = listSheet.FirstOrDefault(x => x.Contains(cCommon.sFDDetailsWorkSheetName));
OleDbCommand cmd = new OleDbCommand(string.Format("SELECT * FROM [{0}]", workSheetName.Trim()), con);
cmd.CommandType = System.Data.CommandType.Text;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
}
Upvotes: 0
Views: 97
Reputation: 3099
Using OleDb for accessing Excel is a possible way, but not the best. I suggest to consider using third party libraries for importing from Excel.
There are two very recommended:
Both are good and will do the job. In addition, they are free and do not require MS Office to be installed on the machine.
Upvotes: 1