Click here to Skip to main content
15,886,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i am having trouble in my program , i want to search the database if it has the word/phrase on the string i typed in. if it was there it will be shown through messagebox else prompt that there isnt. i tried using LIKE in my query but it only search the database that contains the string i typed. i want it to be the opposite...

this is my code i know its horrible please help.

VB
Public Sub searchSpecial(ByVal UserInput)
     conn.ConnectionString = c_string_special
     conn.Close()
     Dim cmd As New OleDbCommand
     Dim dr As OleDbDataReader
     If conn.State = ConnectionState.Closed Then
         conn.Open()
     End If
     With cmd
         .Connection = conn
         .CommandText = "SELECT * FROM fear WHERE sentence LIKE '% %'"
         .CommandType = CommandType.Text
         dr = .ExecuteReader
     End With
     If dr.Read() Then
         Dim x = dr.Item("sentence")
         If x.ToString.Contains(UserInput) Or UserInput.ToString.Contains(x) Then
             MsgBox(UserInput)
         End If
     End If
     conn.Close()
 End Sub
Posted
Comments
_Vitor Garcia_ 21-Nov-12 4:25am    
What's the type of UserInput ? String ?

You are searching for every row in which the sentence fields has something with one space.
Shouldn't you search for something like this ?
.CommandText = "SELECT field1, field2, sentence FROM fear WHERE sentence LIKE '%"& UserInput &"%'"
_Vitor Garcia_ 21-Nov-12 4:27am    
and i don't understand what you mean by "i want it to be the opposite..."

1 solution

You are searching for every row in which the sentence fields has something with one space.
You should search for something, like this :
.CommandText = "SELECT sentence FROM fear WHERE sentence LIKE '%"& UserInput &"%'"
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900