we have data stored in excel file (trail_test.xls), stored in resources folder of our c# project. need load data xls file datagridview on windows form application have.
this code use
system.data.oledb.oledbconnection myconnection; system.data.dataset dtset; system.data.oledb.oledbdataadapter mycommand; string path = system.appdomain.currentdomain.basedirectory + @"resources\trail_test.xls"; myconnection = new system.data.oledb.oledbconnection(@"provider=microsoft.jet.oledb.4.0;data source='" + path + "';extended properties=excel 8.0;"); mycommand = new system.data.oledb.oledbdataadapter("select * [20$]", myconnection); dtset = new system.data.dataset(); mycommand.fill(dtset); datagridview1.columns.clear(); datagridview1.datasource = dtset.tables[0];
this gives error on 8th line:
the microsoft jet database engine not find object '20$'. make sure object exists , spell name , path name correctly.
any ??
thanks
the path has relative executable. example if executable in
c:\users\adham\documents\visual studio 2010\projects\curve fitting\curve fitting\
then path .xls file
string path = system.appdomain.currentdomain.basedirectory + @"resources\trail_test.xls"; string connectionstring = @"provider=microsoft.jet.oledb.4.0;data source='" + path + "';extended properties=excel 8.0;"
Comments
Post a Comment