B
bstauffer
I am importing data from an Excel spreadsheet into a .Net DataTable
using the following code:
// conn string
Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended
Properties="Excel 8.0"
OleDbConnection conn = new
OleDbConnection(String.Format(this.ExcelConnString, ofd.FileName));
OleDbCommand cmd = new OleDbCommand(this.SpreadsheetSelect, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dtAHMOrders = new DataTable();
da.Fill(dtAHMOrders);
The data comes across fine except for zip codes with leading zeros in
which case the leading zeros are lost. I have tried every exampe I've
found with the following results:
When formatting the column as Special>ZipCode the data displays fine
in the spreadsheet but the leading zeros are stripped.
When prepending the zip code with an apostrophe the data displays fine
in the spreadsheet but the leading zeros are stripped.
What is completely frustrating me is that I have a different
spreadsheet which also has leading zeros on zip codes and they import
perfectly!!! When inspecting the Cell Format of this spreadsheet the
cells are formatted as simply General. When looking at all of the
cells show the green wedge in the upper left corner of the cell and
the error says Storing Number as Text. Uppon closer inspection of the
data I find no apostrophes, or spaces, or carrats, or ANYTHING! If I
open a blank spreadsheet and enter 00401 into a cell, which is
formatted as General by default, the leading zeros are lost as soon as
I leave the cell.
Can ANYONE shed some light on this? Thank you.
using the following code:
// conn string
Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended
Properties="Excel 8.0"
OleDbConnection conn = new
OleDbConnection(String.Format(this.ExcelConnString, ofd.FileName));
OleDbCommand cmd = new OleDbCommand(this.SpreadsheetSelect, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dtAHMOrders = new DataTable();
da.Fill(dtAHMOrders);
The data comes across fine except for zip codes with leading zeros in
which case the leading zeros are lost. I have tried every exampe I've
found with the following results:
When formatting the column as Special>ZipCode the data displays fine
in the spreadsheet but the leading zeros are stripped.
When prepending the zip code with an apostrophe the data displays fine
in the spreadsheet but the leading zeros are stripped.
What is completely frustrating me is that I have a different
spreadsheet which also has leading zeros on zip codes and they import
perfectly!!! When inspecting the Cell Format of this spreadsheet the
cells are formatted as simply General. When looking at all of the
cells show the green wedge in the upper left corner of the cell and
the error says Storing Number as Text. Uppon closer inspection of the
data I find no apostrophes, or spaces, or carrats, or ANYTHING! If I
open a blank spreadsheet and enter 00401 into a cell, which is
formatted as General by default, the leading zeros are lost as soon as
I leave the cell.
Can ANYONE shed some light on this? Thank you.