我用“SELECT * FROM User”查询SQL Server Compact数据库,解析查询时出错:
令牌行号= 1,令牌行偏移= 15,令牌错误=用户
我该如何解决这个问题?
我正在使用的代码是:
public static List<User> GetUsers()
{
List<User> users = new List<User>();
using (SqlCeConnection con = new SqlCeConnection(Properties.Settings.Default.DatabaseConnection))
{
con.Open();
using (SqlCeCommand command = new SqlCeCommand("SELECT * FROM " + TABLE, con))
{
SqlCeDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int id = reader.GetInt32(0);
string user = reader.GetString(1);
User usr = null;
using (MemoryStream s = new MemoryStream())
{
NetDataContractSerializer serializer = new NetDataContractSerializer();
s.Write(ASCIIEncoding.ASCII.GetBytes(user.ToCharArray()), 0, user.Length);
s.Position = 0;
usr = (User)serializer.Deserialize(s);
}
}
}
}
return users;
}
注意:尝试添加信息时也会出现此错误。
答案 0 :(得分:1)
看起来令牌“用户”未被理解。只是猜测(我没有要测试的SqlCE)尝试用方括号“引用”表名:
"SELECT * FROM [User]"