Solved

VB.NET sql connection statement syntax question...

Posted on 2004-04-07
3
833 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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