x

Clarification in like command

hi everybody

i am a beginner in sql.. i need a clarification

                    
sqlcommand com=new sqlcommand("Select * from Registration where UserName like %@UserName%",con)                    
com.parameters.add("@UserName",sqldbtype.varchar,128).value='d';                    
sqlDataAdapter adp=new sqlDataAdapter(com);                    
Datattable dt=new Datatable();                    
adp.fill(dt);                    
return dt;                    

but i am not getting the value..how to pass parameter in like command

more ▼

asked Jan 28 '10 at 04:44 AM in Default

Balaji gravatar image

Balaji
1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

Change the SQL to:


Select * from Registration where UserName like '%' + @UserName + '%'

more ▼

answered Jan 28 '10 at 05:15 AM

Kristen gravatar image

Kristen ♦
2.2k 6 7 10

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x472

asked: Jan 28 '10 at 04:44 AM

Seen: 302 times

Last Updated: Jan 28 '10 at 05:14 AM