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.

Recommended Answers

All 8 Replies

Hi,

You can find an example here.

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.

Could you tell me the exact error Message?

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.

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

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.