I'm trying to read data from an Excel File into a DataSet
, but my problem is the DataTable
Column Names aren't matching what's in my Excel. It seems to be only Columns with long Column Names. In the DataTable
Column Names it cuts off at some point.
Here's my attempt:
DataSet mainExcelDataToImport = new DataSet();
using (OleDbConnection mainExcelOleDbConnection = new OleDbConnection())
{
string theMainExcelConnectionString = this.ExcelConnectionString.Replace("{FullFilePath}", this.SelectedFilePath);
mainExcelOleDbConnection.ConnectionString = theMainExcelConnectionString;
// Open
mainExcelOleDbConnection.Open();
string mainExcelSQL = "SELECT * FROM [{ExcelSheet}$]";
mainExcelSQL = mainExcelSQL.Replace("{ExcelSheet}", selectedExcelSheet);
using (OleDbCommand mainExcelOleDbCommand = mainExcelOleDbConnection.CreateCommand())
{
mainExcelOleDbCommand.CommandText = mainExcelSQL;
mainExcelOleDbCommand.CommandType = CommandType.Text;
// Prepare
mainExcelOleDbCommand.Prepare();
using (OleDbDataAdapter mainOleDbDataAdapter = new OleDbDataAdapter(mainExcelOleDbCommand))
{
mainOleDbDataAdapter.Fill(mainExcelDataToImport);
// Close
mainExcelOleDbConnection.Close();
}
}
}
Here's a .xlsx I've tried:
A1234567890123456789012345678901234567890123456789012345678901234567890
TEST
'A12345.....' is the Column Name at A1
'TEST' is the Value at A2
When I check the `ColumnName` in the `DataTable` I get: 'A123456789012345678901234567890123456789012345678901234567890123' which is 64 characters.
How does the ColumnName
MaxLength
limitation work?
Can I get rid of it?
Is it maybe a limitation on the OleDbDataAdapter
?
Any help / suggestions would be appreciated.