Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have this error text "System.Data.OleDb.OleDbException : 'Syntax error in FROM clause.'"
i didn't know why that's doing this error message

Please Can you help me ?

Code :

C#
private void Form1_Load(object sender, EventArgs e)
        {
           
            using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\DataBase\Test.accdb"))
            {
                OleDbCommand command = new OleDbCommand("SELECT * FROM note", con);

                con.Open();
                OleDbDataReader reader = command.ExecuteReader();
                listBox1.Items.Clear();
                while (reader.Read())
                {
                    listBox1.Items.Add(reader[0].ToString());
                }
                reader.Close();
            }

        }


Im just trying to get my Databass Note and to print on listbox

What I have tried:

I have another project with other Databass (more important) and the code didn't have an error what i need to do for my other project please help me.

<pre lang="c#"> using (OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=testapp.accdb"))
            {
                OleDbCommand command = new OleDbCommand("SELECT * FROM T_article",con);

                con.Open();
                OleDbDataReader reader = command.ExecuteReader();
                lbxTableau.Items.Clear();
                while (reader.Read())
                {
                    lbxTableau.Items.Add(reader[0].ToString());
                }
                reader.Close();
            }


i really need to read my databass for my programme :(
Posted
Updated 15-Aug-18 22:42pm

If you use reserved words for tables you put square brackets around them to let it be known you are not referring to the reserved word but a table called that word.

OleDbCommand command = new OleDbCommand("SELECT * FROM [note]", con);
 
Share this answer
 
v2
Comments
Member 13951068 16-Aug-18 4:43am    
Thanks you that's working :D

Have a good day :D
"Note" is an access keyword: Access 2007 reserved words and symbols - Access[^] - to use it as a table name it must be escaped:
C#
OleDbCommand command = new OleDbCommand("SELECT * FROM [note]", con);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900