Query to produce true/false responsce

crazymarvin

Member
Joined
Nov 22, 2006
Messages
18
Location
Belfast, UK
Programming Experience
Beginner
Hi

I am wanting to query a database to find if it contains a record, e.g. search all the the name fields in all the records for "bob" then execute a section of code if bob is found.

Could anyone tell me how to do this, or does anyone of any examples on how to do this?

Thanks
 
You just do your query like normal, and if it returns rows, execute your code.

VB.NET:
strSql = "Select * from Your_Table where name = 'bob'"
dim da as SqlDataAdapter = new SqlDataAdapter(strSql, your_conn)
dim ds as DataSet = new DataSet()

int rows = 0

rows = da.Fill(ds)

if(rows > 0)
    'Code to execute if it found anything
End if
 
Back
Top