error in from clause

  • Thread starter Roel Van den Brande
  • Start date
R

Roel Van den Brande

Hello

I try to fill a dataset. This is my code

string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
source= C:\\Inetpub\\wwwroot\\Notenhof\\data\\notenhof.mdb;";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
myConnection.Open();

DataSet ds = new DataSet();
OleDbDataAdapter dtad = new OleDbDataAdapter("SELECT * FROM
user",myConnection);
dtad.Fill(ds);

When I execute: dtad.Fill(ds); I get the following error:

System.Data.OleDb.OleDbException: Syntax error in FROM clause.

This is very strange because user is a valid table...

Thx for helping me
Roel
 
C

Cor

Hallo Roel,

Is there a special reason for those double sleshes in your Data Source?
(by the way you there is no need to open/close the connection with this kind
of syntax)

I hope this helps?

Cor
 
J

Jon Skeet [C# MVP]

Roel Van den Brande said:
I try to fill a dataset. This is my code

string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
source= C:\\Inetpub\\wwwroot\\Notenhof\\data\\notenhof.mdb;";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
myConnection.Open();

DataSet ds = new DataSet();
OleDbDataAdapter dtad = new OleDbDataAdapter("SELECT * FROM
user",myConnection);
dtad.Fill(ds);

When I execute: dtad.Fill(ds); I get the following error:

System.Data.OleDb.OleDbException: Syntax error in FROM clause.

This is very strange because user is a valid table...

Is "user" perhaps a reserved word which needs to be quoted/escaped
somehow?
 
R

Roel Van den Brande

Hi all

Adding brackets around table user is the solution. This because user is a
reserved word.

I need to add double slashes in the datasource because it won't work with
one slash.

Many thx !
Roel
 
J

Jon Skeet [C# MVP]

Cor said:
Is there a special reason for those double sleshes in your Data Source?

Yes, \ is an escape character in C#, so it needs to be doubled to
include it in a string, unless a verbatim string literal is used (an @
at the start of the string).
(by the way you there is no need to open/close the connection with this kind
of syntax)

True.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top