These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: LIKE in CreateQuery
PostPosted: Tue Jun 03, 2008 8:45 am 
Beginner
Beginner

Joined: Fri Feb 29, 2008 9:36 am
Posts: 40
Hi,

I need to create a query with like expression on a string column.
This query need to run on Access, MySQL, SQL Server, Oracle.

Actually, my code is:

Code:
result = session.CreateQuery("select count(*) from PatientsEntity where enabled <> 0 and DisplayName like :DisplayName")
    .SetString("DisplayName", "\"" + expression + "*\"")
    .UniqueResult<System.Int64>();


Example: in my code, "\"" + expression + "*\"" return "JE*"

When I run my code, I get:

Code:
could not execute query
[ select count(*) as x0_0_ from Patients patientsen0_ where (enabled<>0 )and(DisplayName like ? ) ]
  Name: DisplayName - Value: "*"
[SQL: select count(*) as x0_0_ from Patients patientsen0_ where (enabled<>0 )and(DisplayName like ? )]


What's the real way to initialize the DisplayName parameter please ?

Papy


Top
 Profile  
 
 Post subject: Solution
PostPosted: Tue Jun 03, 2008 10:42 am 
Beginner
Beginner

Joined: Fri Feb 29, 2008 9:36 am
Posts: 40
Code:
qr.SetParameter("last_name", expression + "%", NHibernate.NHibernateUtil.String);


Top
 Profile  
 
 Post subject: Solution
PostPosted: Tue Jun 03, 2008 10:42 am 
Beginner
Beginner

Joined: Fri Feb 29, 2008 9:36 am
Posts: 40
Code:
qr.SetParameter("last_name", expression + "%", NHibernate.NHibernateUtil.String);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.