【问题标题】:mvc3 dapper parameter issuemvc3 dapper 参数问题
【发布时间】:2013-03-07 20:24:55
【问题描述】:

我的 dapper 工作正常,但它不安全,因为我没有使用参数,我怎样才能最好地将我的 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();

我绝对没有返回,但没有错误消息。我在这里可以缺少什么或参数化变量的最佳方法是什么。

【问题讨论】:

    标签: asp.net-mvc-3 parameters dapper


    【解决方案1】:

    您不需要在参数周围加上单引号。希望这可以帮助。

    var getinfo = sqlConnection.Query<test>("Select name,location from tests where location=@location", new {location = myplace}).FirstOrDefault();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 2011-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 2011-11-06
      相关资源
      最近更新 更多