Hello All,
I write the following code to access Data from a table
But i get the exception "Syntax Error in From Clause"

when i write the code in SQL then it works perfectly.

OleDbConnection Myconnection = null;

OleDbDataReader dbReader = null;

Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\STTS.mdb");

Myconnection.Open();

OleDbCommand cmd = Myconnection.CreateCommand();

cmd.CommandText = "SELECT * FROM user";

dbReader = cmd.ExecuteReader();

string Email;

while(dbReader.Read())

{

Email = (string)dbReader.GetValue(0);

lb.Items.Add(Email);

}

dbReader.Close();

Myconnection.Close();



Can anybody tell me where is the error

Thanks

Error Accessing ACCESS.MDB by dip

dip
Tue Sep 02 10:18:09 CDT 2003

try setting your CommandText as :
cmd.CommandText = "select * from [user]"

- dip
>-----Original Message-----
>Hello All,
>I write the following code to access Data from a table
>But i get the exception "Syntax Error in From Clause"
>
>when i write the code in SQL then it works perfectly.
>
>OleDbConnection Myconnection = null;
>
>OleDbDataReader dbReader = null;
>
>Myconnection = new OleDbConnection
(@"Provider=Microsoft.Jet.OLEDB.4.0; User
>Id=; Password=; Data Source=C:\STTS.mdb");
>
>Myconnection.Open();
>
>OleDbCommand cmd = Myconnection.CreateCommand();
>
>cmd.CommandText = "SELECT * FROM user";
>
>dbReader = cmd.ExecuteReader();
>
>string Email;
>
>while(dbReader.Read())
>
>{
>
>Email = (string)dbReader.GetValue(0);
>
>lb.Items.Add(Email);
>
>}
>
>dbReader.Close();
>
>Myconnection.Close();
>
>
>
>Can anybody tell me where is the error
>
>Thanks
>
>
>.
>

Re: Error Accessing ACCESS.MDB(Solve) by Shayer

Shayer
Tue Sep 02 10:42:53 CDT 2003

Hi Dip

thanks for ur reply. Yap i think it will work.
I already change the table name and try and it works. i think that because
of table name which might be an key word.

THanks

"dip" <bom2180@yahoo.com> wrote in message
news:010501c37165$6adc3d80$a101280a@phx.gbl...
> try setting your CommandText as :
> cmd.CommandText = "select * from [user]"
>
> - dip
> >-----Original Message-----
> >Hello All,
> >I write the following code to access Data from a table
> >But i get the exception "Syntax Error in From Clause"
> >
> >when i write the code in SQL then it works perfectly.
> >
> >OleDbConnection Myconnection = null;
> >
> >OleDbDataReader dbReader = null;
> >
> >Myconnection = new OleDbConnection
> (@"Provider=Microsoft.Jet.OLEDB.4.0; User
> >Id=; Password=; Data Source=C:\STTS.mdb");
> >
> >Myconnection.Open();
> >
> >OleDbCommand cmd = Myconnection.CreateCommand();
> >
> >cmd.CommandText = "SELECT * FROM user";
> >
> >dbReader = cmd.ExecuteReader();
> >
> >string Email;
> >
> >while(dbReader.Read())
> >
> >{
> >
> >Email = (string)dbReader.GetValue(0);
> >
> >lb.Items.Add(Email);
> >
> >}
> >
> >dbReader.Close();
> >
> >Myconnection.Close();
> >
> >
> >
> >Can anybody tell me where is the error
> >
> >Thanks
> >
> >
> >.
> >



Re: Error Accessing ACCESS.MDB by Paul

Paul
Wed Sep 03 07:21:36 CDT 2003

On Tue, 2 Sep 2003 23:40:37 +1000, "Shayer" <shayer009@hotmail.com> wrote:

¤ Hello All,
¤ I write the following code to access Data from a table
¤ But i get the exception "Syntax Error in From Clause"
¤
¤ when i write the code in SQL then it works perfectly.
¤
¤ OleDbConnection Myconnection = null;
¤
¤ OleDbDataReader dbReader = null;
¤
¤ Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User
¤ Id=; Password=; Data Source=C:\STTS.mdb");
¤
¤ Myconnection.Open();
¤
¤ OleDbCommand cmd = Myconnection.CreateCommand();
¤
¤ cmd.CommandText = "SELECT * FROM user";
¤

The field name "User" is an SQL ODBC reserved word. Use dip's suggestion to work around the issue.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)