Another SQL question

Status
Not open for further replies.

maddmurph

Ars Tribunus Militum
1,986
Ok, I have these SQL statements for a Visual Basic homework project, that search a database, and I want to change it from an exact search like it has now to one that can do "not exact" searches. I know that I need to put in "LIKE" somewhere in the statements I am just unsure of where I have to put it


If OptfindCD = True Then
sqlcount = "SELECT count(*) from [CD Explorer] where [CD Name] = " + QUOTE + txtsearch.Text + QUOTE
SqlStmt = "SELECT [CD Name], [Path], [File Name] from [CD Explorer] where [CD Name] = " + QUOTE + txtsearch.Text + QUOTE
ElseIf optfindfile = True Then
sqlcount = "SELECT count(*) from [CD Explorer] where [File Name] = " + QUOTE + txtsearch.Text + QUOTE
SqlStmt = "SELECT [CD Name], [Path], [File Name] from [CD Explorer] where [File Name] = " + QUOTE + txtsearch.Text + QUOTE
End If

Is it supposed to be where the "=" sign is?
 

MrCatbert

Ars Tribunus Angusticlavius
9,107
Subscriptor
sqlcount = "SELECT count(*) from [CD Explorer] where [CD Name] LIKE " + QUOTE + txtsearch.Text + QUOTE

You can also do searches that include wildcards

sqlcount = "SELECT count(*) from [CD Explorer] where [CD Name] LIKE " + QUOTE + "%" + txtsearch.Text + "%" + QUOTE

The % character acts as the wildcard argument and can be placed within the comparison string where desired...
 
Status
Not open for further replies.