Reputation: 243
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 * from [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 am getting exception "Syntax error in from clause" for the line of code starting at data1. This line calls the function below it DatabaseTables which generates this exception. I have also included the connection string which uses jet etc in the fn SetConnection. I think the problem could be the connection string itself. Currently i have to leave the excel file open to prevent a "could not decrypt" error. I did try the ACE driver but got errors. The excel work book is saved as a 97-03 workbook.
Upvotes: 1
Views: 2171
Reputation: 5636
change
data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$])", DataAccess.database);
with
data1 = DataAccess.DatabaseTables("SELECT * from [Sheet1$]", DataAccess.database);
There is one extra closing bracket.
Hope it works.
Upvotes: 1