错误:
[token line number = 1,token line offset = 15,token in error = %]
我的代码:
SqlCeCommand cmd = con.CreateCommand();
cmd.Connection = con;
cmd.CommandText = "select emails from contacts where name like %@name";
cmd.Parameters.AddWithValue("@name", name);
SqlCeDataReader data = cmd.ExecuteReader();
//..
我相信这是因为查询中的@name。
我也试过了:select emails from contacts where name like '%@name'
我是如何解决的?谢谢!
答案 0 :(得分:2)
您需要在SQL解析器中隐藏%
,因为它是字符串文字的一部分:
SqlCeCommand cmd = con.CreateCommand();
cmd.Connection = con;
cmd.CommandText = "select emails from contacts where name like @name";
cmd.Parameters.AddWithValue("@name", "%"+name);
SqlCeDataReader data = cmd.ExecuteReader();
答案 1 :(得分:1)
你应该试试这个:
select emails from contacts where name like '%'+@name