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();
}
Try this instead:
SqlCeCommand cm = new SqlCeCommand("SELECT * FROM [users-tbl]", cn);