Hi,
I am trying to load an Excel file into a datatable. Most of the cells get loaded but some don't!
For example a cell would show as null but the others show good.
The input was good enough for MS-Access to load successfully showing all data. So the problem is in my code.
Here is the code:
//-----------------------------------------------------------------------------------------------------------
private
void button1_Click(object sender, EventArgs e){
string part1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; string part2 = ";Extended Properties=Excel 8.0;"; string fn = "C:\..\A.xls"; '<-- fix if you want to test on your machine string cnStr = part1+fn+part2;System.Data.OleDb.
OleDbConnection cn = new OleDbConnection(cnStr);cn.Open();
DataTable dt = new DataTable("Results"); OleDbCommand cmd;cmd =
new System.Data.OleDb.OleDbCommand("Select * from [Sheet1$]", cn); OleDbDataAdapter da = new OleDbDataAdapter(cmd);dt.Clear();
da.Fill(dt);
MessageBox.Show(dt.Rows[0][0].ToString()); <-- Cell Shows empty!! Most of the other cells are gooddataGridView1.DataSource = dt;
If you want the sample data tell me how to send it to you - I see no file upload option on this forum!!