Solved

VB.NET sql connection statement syntax question...

Posted on 2004-04-07
3
827 Views
Last Modified: 2009-07-29
I need to query a DB using a variable from a textbox.  The strSearch will hold the string to search for using the LIKE option.

How do I use a variable (strSearch) in the SQL statement with the % wildcard?  

Where (T4.PROJ_ID LIKE %'strSearch'%)  ???  That isn't right...

Is this SQL syntax or VB?

Thanks in advance...
0
Comment
Question by:Weller0123
3 Comments
 
LVL 6

Assisted Solution

by:KarunSK
KarunSK earned 167 total points
ID: 10778816
Is this what you want?

Dim strWhereClause As String = "Where (T4.PROJ_ID LIKE '%" & strSearch & "%')"

0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 167 total points
ID: 10778828
String WhereClause = "Where T4.PROJ_ID LIKE %" & txtSearch.Text.Replace("'","''") & "%'";

WhereClause = WhereWhere T4.PROJ_ID LIKE '%TEXT%'

that will find anything with txtSearch.text in it ...
use a % for wild chars anywhere in the string

remember to either use the sqltypes or to escape things like ' out of your field otherwise someone can use it to attack your database
0
 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 166 total points
ID: 10778831
the one way is to use parameters
if you want to build direct the sql statement
you can use
"select * from T4 where (T4.Proj_ID Like '%" & strSearch & "%')"

hth
b..m
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now