I want to search the records from the textbox and display the records to the datagridview, if there are no records, just display empty on the datagridview.

this is not working:

Dim sqlsearch As String
sqlsearch = "SELECT * FROM setting WHERE mname LIKE '%" & TextBox.Text
Dim adapter As New OleDbDataAdapter(sqlsearch, con1)
Dim dt As New DataTable("setting")
adapter.Fill(dt)
Form2.DataGridView1.DataSource = dt

RefreshDGV()

THANKS.

in you code there is mistakes quotes so write true code. write your code like this

sqlsearch = "SELECT * FROM [setting] WHERE [mname] LIKE ' " & TextBox.Text & " ' ;"

try this code.

Hi,

You can find an example here.

It is great, but I want to know how to display them in datagridview.

Anyway,thanks all, actually it is still not working.

Edited 6 Years Ago by needanswer: n/a

Could you tell me the exact error Message?

Actually, the error is on

sqlsearch = "SELECT * FROM setting WHERE mname LIKE '%" & TextBox.Text

This is making that couldn't do the display, I changed it to

sqlsearch = "SELECT * FROM setting WHERE mname LIKE '%" 
& TextBox1.Text & "%'"

IT is definitely working.

Edited 6 Years Ago by needanswer: n/a

remove the first % after the like keyword and try. if you are working with ms access hen don't write '%' it will not work for the ms access
instead of try this

sqlsearch = "SELECT * FROM [setting] WHERE [mname] LIKE ' " & trim(TextBox.Text) & " ' ;"

if you want to bind datagrid view with dataset then write this code

''write connection and  open it
   Dim str As String
   dim     ds as DataSet
        str = "SELECT * FROM [setting] WHERE [mname] LIKE ' " & trim(TextBox.Text) & " ' ;"
        da = New SqlDataAdapter(str, con) ''its sqlDataadapter
        da.Fill(ds, "setting")  ''fill  with your table
        dgv2.DataSource = ds  ''dgv2 is a datagridview name
        dgv2.DataMember = "setting"

try this code for datagrid

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