简体   繁体   English

在查询字符串上找不到参数

[英]Can't find parameter on querystring

I have a query string in which the parameter want this between apostrophes : 我有一个查询字符串,其中的参数需要在撇号之间:

select * from myTable t
where t.name= ':name'

However when debugging the code he tells me not find the parameter : 但是,在调试代码时,他告诉我找不到参数:

protected bool validName(string n, NHibernate.ISession sesion){


var result= sesion.CreateSQLQuery(Queries.getQuery("queryName"))
                .SetParameter("name", n)
                .UniqueResult();

The Query parser should apply the sql statements for your. 查询解析器应为您应用sql语句。 Try doing your query like this: 尝试像这样进行查询:

select * from myTable t where t.name = :name

I would recommend you using HQL , for sample: 我建议您使用HQL作为示例:

var result = session.CreateQuery("from Entity t where t.name = :name")
                    .SetParameter("name", n)
                    .UniqueResult();

Where Entity is the entity that references your table (by mapping). 其中, Entity是引用您的表的实体(通过映射)。

Apostrophes are used to indicate a literal string. 撇号用于指示文字字符串。 They should and can not be used around parameter names. 它们应该也不能在参数名称周围使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM