我有精巧的工作正常,但它是不安全的,因为我没有使用参数,我怎样才能最好地将我的dapper变量转换为参数,例如这是我所用的非参数化代码..
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location="+ myplace).FirstOrDefault();
myplace是用户放置信息的文本框,现在当我尝试参数化代码时
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location='@location'", new {location = myplace}).FirstOrDefault();
我绝对没有返回,但没有错误消息。我在这里可以缺少什么,或者是参数化变量的最佳方法。
您不需要在参数周围放置单引号。希望这可以帮助。
var getinfo = sqlConnection.Query<test>("Select name,location from tests where location=@location", new {location = myplace}).FirstOrDefault();