c# - Why won't my datatable populate -
i have searched long time , can't find i'm doing wrong.
i have web app uploads spreadsheet (verified works) , supposed parse spreadsheet , populate gridview. seems simple enough, won't display data.
the spreadsheet i'm testing (as upload; upload works expected) simple single tab spreadsheet boring vanilla... 3 columns column names 1 row of data (two populated rows total, destined expanded once thing works). tab name crprlist
used in oledbdataadapter
below.
i'm getting no errors on page, gridview not populate.
here's gridview in asp.net:
<asp:gridview id="topicstbl" runat="server" allowsorting="false" allowpaging="false" autogeneratecolumns="false"> <columns> <asp:boundfield headertext="cr" datafield="cr" /> <asp:boundfield headertext="pr" datafield="pr" /> <asp:boundfield headertext="summary" datafield="summary" /> </columns> </asp:gridview>
i've got down following code. mean i've tested down this. no errors , things seem work expected... except gridview won't populate:
oledbdataadapter adapter = new oledbdataadapter("select * [crprlist$]", xlsconnect); dataset ds = new dataset(); adapter.fill(ds, "crprlist"); datatable data = ds.tables["crprlist"]; topicstbl.datasource = data;
the xlsconnect
string depend on wether or not file xls or xlsx:
string strconn; if (filetype.tolower() == "xls" || filetype.tolower() == "xlsx") { strconn = (filetype == "xlsx") ? string.format("provider=microsoft.ace.oledb.12.0;data source={0};extended properties=\"excel 12.0\"", filepath) : string.format("microsoft.jet.oledb.4.0;data source={0};extended properties=\"excel 8.0\"", filepath); xlsconnect = new oledbconnection(strconn); return true; } else return false; //throw new exception("file extension not registering");
what missing? or doing wrong?
i'm guessing gridview not set right, or spreadsheet parsing understanding not complete... way off though!
thanks
you have bind data:
datatable data = ds.tables[0]; topicstbl.datasource = data; topicstbl.databind();
Comments
Post a Comment