c# - Syntax Error in From clause Excel -
public void setconnection(string text1, string text2, string text3, string text4, string text5, string text6, string text7) { connectionstring1 = "initial catalog=testdb; data source=work\\sqlexpress"; database = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source='c:\\users\\test.xls';extended properties= \"excel 8.0;hdr=yes;imex=1\";"); database.open(); database1 = new oledbconnection("provider=sqloledb.1;" + connectionstring1); database1.open(); } data1 = dataaccess.databasetables("select * [sheet1$])", dataaccess.database); public datatable databasetables(string querystring, oledbconnection dataconnection) { oledbcommand sqlquery = new oledbcommand(); datatable data = null; sqlquery.connection = null; oledbdataadapter dataadapter = null; sqlquery.commandtext = querystring; sqlquery.connection = dataconnection; data = new datatable(); dataadapter = new oledbdataadapter(sqlquery); dataadapter.fill(data); return data; } i getting exception "syntax error in clause" line of code starting @ data1. line calls function below databasetables generates exception. have included connection string uses jet etc in fn setconnection. think problem connection string itself. have leave excel file open prevent "could not decrypt" error. did try ace driver got errors. excel work book saved 97-03 workbook.
change
data1 = dataaccess.databasetables("select * [sheet1$])", dataaccess.database); with
data1 = dataaccess.databasetables("select * [sheet1$]", dataaccess.database); there 1 closing bracket.
hope works.
Comments
Post a Comment