Error Accessing Data from Access Database

S

Shayer

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
 
N

Nicholas Paldino [.NET/C# MVP]

Shayer,

Can you provide a copy of the STTS.MDB file? The command is simple
enough that it seems like it should work. The only thing I can think of
would be to check the cmd variable and see that the command is not trying to
execute a stored procedure or something like that (I don't know what the
defaults for the instance returned from the CreateCommand method are).

Hope this helps.
 
N

NULL

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.
Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\STTS.mdb");

Check out www.connectionstrings.com for appropriate connectionstrings
for an Access DB (nice site :) very usefull):
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=;"
cmd.CommandText = "SELECT * FROM user";

try:
cmd.CommandText = "SELECT * FROM [user]"; //NOTE the []

BTW, is 'user' thegood table (does it exist? I suppose so because the
error would be another if it did not, but I'm just confirming)
 
N

NULL

On Tue, 2 Sep 2003 09:45:47 -0400, "Nicholas Paldino [.NET/C# MVP]"

Hey...

What does C# MVP (Most Valued Partner??) mean... What do you have to
do to be allowed to carry that title?
 
S

Shayer

Hello

Everyyhing is okay here

I have to replace the table name. I have a user table . I think User is a
key word , i have to replace it . IF i replace it , it works perfectly

thanks

NULL said:
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.
Myconnection = new OleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0; User
Id=; Password=; Data Source=C:\STTS.mdb");

Check out www.connectionstrings.com for appropriate connectionstrings
for an Access DB (nice site :) very usefull):
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=;"
cmd.CommandText = "SELECT * FROM user";

try:
cmd.CommandText = "SELECT * FROM [user]"; //NOTE the []

BTW, is 'user' thegood table (does it exist? I suppose so because the
error would be another if it did not, but I'm just confirming)
 

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