• Coding
  • vb.net search function issue

hey,
i'm trying to write a small thing with vb.net using visual studio 2008
and i am new to VB and the .net framework
however after some google'ng i managed to understand few stuff and i wrote a small example where i have a button, text box and a DataGridView
the user enter a word in the text box and click the button
the program search the database basing on the user word

however it is not working, can anyone help me.
this is the code

the error is at this line "da.fill(ds)" it says No value given for one or more required parameters.
this is the whole code
Imports System.Data.OleDb

Public Class Form1
    Dim query As String
    Dim kword As String

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim dbConn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\db.accdb;User Id=admin;Password=;")
        dbConn.Open()
        Dim ds As New DataSet
        kword = txtSearch.Text.ToString
        query = "SELECT * from Table1 where addres LIKE " + kword
        Dim da As New OleDbDataAdapter(query, dbConn)
        da.Fill(ds)
        dgv.DataSource = ds.Tables(0)
        da.Dispose()
        dbConn.Close()


    End Sub
End Class
you've missed the OledbCommand class which you use to query your database
check : http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand(v=vs.71).aspx

the code is something like this:

 
Dim cmd As New OleDbCommand(query, dbConn)
Dim param As New OleDbParameter("@param", kword)
cmd.Parameters.Add(param)
Dim da As New OleDbDataAdapter(cmd)
also you are using the "Like operator" to search for the specific value or all containing values in your textfield?
because the way you are using it you're missing the "%" sign to search different patterns, using "=" instead of like would return the same result.

check: http://www.w3schools.com/sql/sql_like.asp