SOL1:-
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strValue + ";Extended Properties=\"Excel 8.0;HDR=NO\"";
cn.ConnectionString = sConnectionString;
cn.Open();
string sSQL = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = cn.CreateCommand();
cmd.CommandText = sSQL;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(excelList);
dataGridView1.DataSource = excelList;
---------------------------------------------------------------------------------
Hi everyone,
I have the above code to call a excel, but when the field is a date and the vaue is also a date, there is nothing to show in my datagridview... it is not showing the 5 digit date value either.....
-------------------------------------------------------------------------------------
SOL2:-
Please set the datasource of datagridview to a table as bellow:
DataSet ds = new DataSet();
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
If the problem still arise , Please try to download the application to see if it works:
http://cid-219dc49fbdfffbd1.skydrive.live.com/self.aspx/Public/WindowsFormsApplication5.rar
No comments:
Post a Comment