There was an error parsing the query. [ Token line number = 1,Token line offset = 20,Token in error = - ] C#

soheil yo picture soheil yo · Jul 10, 2015 · Viewed 9.5k times · Source

I am using a SQL Server Compact 3.5 database file (.sdf) in C#; with the code I can read from albums_tbl but I want to read from users-tbl or other tables it errors :

There was an error parsing the query. [ Token line number = 1,Token line offset = 20,Token in error = - ]

albums_tbl table has two columns: id, name

this is my code :

 private void loginbtn_Click(object sender, EventArgs e)
        {
            SqlCeConnection cn = new SqlCeConnection(@"Data Source = C:\com_honar\test1.sdf ");

            cn.Open();

            SqlCeDataReader rdr = null;
            SqlCeCommand cm = new SqlCeCommand("SELECT * FROM users-tbl ", cn);
            rdr = cm.ExecuteReader();

            while (rdr.Read())
            {
                label1.Text = rdr.GetString(1);

            }
            rdr.Close();
        }

enter image description here

enter image description here

Answer

Thanos Markou picture Thanos Markou · Jul 10, 2015

Try this instead:

SqlCeCommand cm = new SqlCeCommand("SELECT * FROM [users-tbl]", cn);