I have this code:
public void FillData()
{
// 1 step. Open connection
string conection = @"Data Source=|DataDirectory|db.sdf;Persist Security Info=False;";
try
{
SqlCeConnection c = new SqlCeConnection(conection);
c.Open();
// 2 step. Create new DataAdapter
using (SqlCeDataAdapter a = new SqlCeDataAdapter("SELECT * FROM USER", c))
{
// 3 step. Use DataAdapter to fill table
DataTable t = new DataTable();
a.Fill(t);
// 4 step. Render data on the DataGridView
dataGridViewUsers.DataSource = t;
}
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
}
I can connect to the database, but the SqlCeDataAdapter launches this mistake:
There was an error parsing the query. [Token line number = 1, Token line offset = 15, Token in error = USER]
My database has a table named USER, so what’s wrong with this code??
USER is reserve word. Pass it like
[USER]in your query. Your query should look like.