Firstly, I want to say that here I am in deep water, since I just make some changes in the code written by someone else in the company, using the OleDbDataAdapter to “talk” with Excel, m is not familiar with this. There is one mistake that I simply cannot follow.
I am trying to use an OleDbDataAdapter to read in an excel file with about 450 lines.
In code, this is done as follows:
connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source='" + path + "';" + "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;\""); connection.Open(); OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCommand.CommandText, connection); objAdapter.Fill(objDataSet, "Excel"); foreach (DataColumn dataColumn in objTable.Columns) { if (dataColumn.Ordinal > objDataSet.Tables[0].Columns.Count - 1) { objDataSet.Tables[0].Columns.Add(); } objDataSet.Tables[0].Columns[dataColumn.Ordinal].ColumnName = dataColumn.ColumnName; objImport.Columns.Add(dataColumn.ColumnName); } foreach (DataRow dataRow in objDataSet.Tables[0].Rows) { ... }
Everything seems to be working fine, except for one. The second column is filled mainly with four numeric digits, such as 6739, 3920 and so on, but the rows of the rows have alphanumeric values, such as 8201NO and 8205NO. These five cells are reported as having empty content instead of their alphanumeric content. I checked in excel and all cells in these columns are marked as Text.
This is an xls file, by the way, not an xlsx.
Does anyone have a clue why these cells are displayed as empty in the DataRow, but are the numbers shown well? There are other columns with alphanumeric content that are shown just fine.
c # excel jet oledbconnection
Øyvind Bråthen
source share