Click here to Skip to main content
12,349,349 members (70,744 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
Minazeh171
Comments
VitorHugoGarcia 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2016
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