Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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.
 
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 20-Nov-12 22:19pm
Minazeh165
Comments
VitorHugoGarcia at 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 &"%'"
VitorHugoGarcia at 21-Nov-12 4:27am
   
and i don't understand what you mean by "i want it to be the opposite..."

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 &"%'"
  Permalink  
v4

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 487
1 CPallini 345
2 OriginalGriff 240
3 George Jonsson 159
4 Abdul Samad KP 145
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100