i have a datagrid view. i am using data table to display data

oledbcon.Open()
        m_daDataAdapter = New OleDb.OleDbDataAdapter("Select * from Customer", oledbcon)
        m_daDataAdapter.Fill(m_dtCustomer)
        m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
        m_rowPosition = m_dtCustomer.Rows.Count
        dataGridView1.DataSource = m_dtCustomer
        oledbcon.Close()

this works great.

later i want to display only those records tht the user types in the text box. so i use this code

Dim oledbcom As New OleDb.OleDbCommand
        oledbcom.CommandText = "Select * from Customer where Company like ?"
        oledbcom.Connection = oledbcon

        oledbcon.Open()

        oledbcom.Parameters.Add("?", OleDb.OleDbType.VarChar)
        Dim company As String = txtSearch.Text.Trim
        oledbcom.Parameters(0).Value = "*" & company.ToString & "*"

        Dim da As New OleDb.OleDbDataAdapter(oledbcom)
        Dim dt As New DataTable
        da.Fill(dt)
        dataGridView1.DataSource = dt

no data is displayed when this code is executed in the text changed event
m using access 2007.

Recommended Answers

All 7 Replies

just a guess, but i think you are missing the last line.

dt.DataBind()

commented: No, it's window control. -2
dataGridView1.Datasource=Nothing
dataGridView1.Datasource=Nothing

i tried this but it did not work
is there any other error

intellisense doesnt show any option related to databind
dt.databind doesnt exist

i tried using data reader and figured out one thing
its not executing the like query instead it looks for the folllowing pattern
* + contents in the text box + *
its looking for the exact match including the asteriks

how do i use the like operator along with the wild card
plz help

got it
using * doesnt help
% should be used instead
thnx neways

try this
'%" + field.Text .toString()+ "%'
or
'%" + field.Text + "%'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.