Hi friemds,

I have a form which contains one textbox and datagridview.
I wnt what,
When i type e in textbox ,all records should be displayed which name is begining with e from table in access.
I have each 5 records which is begining with a,b,c

when i press b all records are displayed of b and one record of a.

I don't understand why it is???
I m sending code.
Anybody can help me plz????

Public Function getSearch(ByVal tableName As String, ByVal field As String, ByVal val As String) As DataTable
        dt = New DataTable
        cmd = New OleDbCommand("select * from " & tableName & " where " & field & " like '" & val & "%' and status='Add' or status='Edit'")
        cmd.Connection = con

        da = New OleDbDataAdapter(cmd)
        da.Fill(dt)
        Return dt
    End Function


Public Function getTable(ByVal tableName As String, ByVal field As String) As DataTable
        Try
            cmd = New OleDbCommand("select * from " & tableName & " where status='Add' or status='Edit' order by " & field)
            cmd.Connection = con
            dt = New DataTable
            da = New OleDbDataAdapter(cmd)
            da.Fill(dt)
            Return dt
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        Finally
            cmd = Nothing
            da = Nothing
        End Try
    End Function



    Private Sub DataGridView2_VisibleChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView2.VisibleChanged
        txtGInvNo.Text = ""
        txtGChallanNo.Text = ""
        cmbGCustomerName.Focus()
        dt = New DataTable
        dt = ob.getTable("SalesInvoice", "InvNo")
        DataGridView2.DataSource = dt
        DataGridView2.Columns(0).Visible = False
        DataGridView2.Columns(20).Visible = False
        DataGridView2.Columns(21).Visible = False
        DataGridView2.Columns(22).Visible = False
    End Sub


  Private Sub txtGVehicleNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtGVehicleNo.TextChanged
        s = txtGVehicleNo.Text
        dt = New DataTable
        dt = ob.getSearch("SalesInvoice", "vehicleNo", s)
        dv = New DataView(dt)
        dv.Sort = "vehicleNo"
        DataGridView2.DataSource = dv
        DataGridView2.Columns(0).Visible = False
        DataGridView2.Columns(20).Visible = False
        DataGridView2.Columns(21).Visible = False
        DataGridView2.Columns(22).Visible = False
    End Sub

hello!

I think the problem is in your query in your getSearch Function.
Try to change "OR" to "AND"
Hope it works!
God bless!

This article has been dead for over six months. Start a new discussion instead.