I am trying read an excel file and once read, want to have it as a datasource for a gridview.
I have following code, the datatable gets populated fine, But some reason, it doesn't refresh the gridview. Not sure why, can someone help please?
string connPath = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";ExtendedProperties = \"Excel 8.0;HDR=Yes;\";";
OleDbConnection conn = new OleDbConnection(connPath);
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM ["+aSheet+"$]", conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
aGridView.DataSource = dt;
aGridView.DataBind();
how about putting something like this
DataTable dt = new DataTable();
DataSet ds = new Dataset();
BindingSource bs = new BindingSource();
adapter.Fill(dt);
ds = dt.Tables[0].DefaultView
bs.DataSource = ds;
aGridView.DataSource = bs.DataSource;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.