search for sting in database


New member
Jul 20, 2012
Programming Experience
Hello Guys,

I have a database that contains a lot of text (like a page full). I want to be able to search the database for a particular string of text or word in the database. i have a textbox on my form where the user is going to enter the input text/ string.

For example: i have this text in the database

<!-- start slipsum code -->

Now that we know who you are, I know who I am. I'm not a mistake! It all makes sense! In a comic, you know how you can tell who the arch-villain's going to be? He's the exact opposite of the hero. And most times they're friends, like you and me! I should've known way back when... You know why, David? Because of the kids. They called me Mr Glass.
Normally, both your asses would be dead as ****ing fried chicken, but you happen to pull this **** while I'm in a transitional period so I don't wanna kill you, I wanna help you. But I can't give you this case, it don't belong to me. Besides, I've already been through too much **** this morning over this case to hand it over to your dumb ass.
Now that there is the Tec-9, a crappy spray gun from South Miami. This gun is advertised as the most popular gun in American crime. Do you believe that ****? It actually says that in the little book that comes with it: the most popular gun in American crime. Like they're actually proud of that ****.

I want to be able to search for the text "hand it over" that will be entered in a the textbox on the form and display the search results in a list box in this format

it takes some text to the left and right of the search string eg. case to hand it over to your

I keep getting this error message: Expected query name after EXECUTE.

Please any suggestions on how to go about this?


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim feed As String

        feed = TextBox2.Text
        Dim con As OleDbConnection = New OleDbConnection()

        con.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\scrollDatabase.mdb"
        Dim sqlCmd As OleDbCommand = New System.Data.OleDb.OleDbCommand()

        sqlCmd.CommandType = CommandType.StoredProcedure
        sqlCmd.CommandText = "SELECT * [Scroll] tablename WHERE Scroll LIKE '*" & Trim(TextBox2.Text) & "*'"
        sqlCmd.Connection = con


        Dim reader As OleDbDataReader

        reader = sqlCmd.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()
                Console.WriteLine(reader("Scroll")) 'output specific column
            End While
        End If

    End Sub


Well-known member
Sep 9, 2012
Healing, NE Lincs, UK
Programming Experience

The reason that you are getting this error is due to the fact that you are passing an SQL String to the Database and yet you are also telling the Database that you want to use a Stored Procedure which is incorrect. This should be of type Text.

In addition to this your SQL String itself is incorrectly formatted. It should be formatted as follows:-

SELECT <fields> FROM <tableName/queryName> WHERE <your criteria if any>

Have a look at this example:-

Dim accConn As New OleDb.OleDbConnection("Your Connection String")
Dim myCommand As New OleDb.OleDbCommand
With myCommand
  .Connection = accConn
  .CommandType = CommandType.Text
  .CommandText = "Select * From Invoices Where CustomerID = 'VINET'"
End With

You should also look at using Parameters to add variable information to your Command object rather than string concatenation.

Hope that helps.


Top Bottom