Reputation: 125
I am using Microsoft Access to create a "Desktop Database" and saved it as "new.mdb" into my C# Debug folder.
However, upon using the SELECT statement, my C# project throws an Exception.
This is my database
And this is my code
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=new.mdb");
conn.Open();
dataset = new DataSet();
string sqlStatement = "SELECT * FROM User";
dbAdapter = new OleDbDataAdapter(sqlStatement, conn);
oOrderDetailsCmdBuilder = new OleDbCommandBuilder(dbAdapter);
dbAdapter.Fill(dataset);
contactsTab = dataset.Tables[0];
contactsTab.TableName = "User";
rows = contactsTab.Rows;
The error upon executing that code is
Syntax error in FROM clause.
However, the query looks fine. Is there anything wrong?
Thanks!
EDIT :
OleDbCommand.ExecuteNonQuery
(Example : Creating new table) works for this. I'm not sure why SELECT statement doesn't :/
Upvotes: 1
Views: 250
Reputation: 1502
User is a reserved keyword in SQL. So write SQL like below
string sqlStatement = "SELECT * FROM [User]";
Upvotes: 2