0

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.

4
Contributors
7
Replies
11
Views
8 Years
Discussion Span
Last Post by g@sha
-1

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

dt.DataBind()

Votes + Comments
No, it's window control.
0
dataGridView1.Datasource=Nothing

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

0

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

0

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

0

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.