Hi. I'm using a datagridview to display data and make updates to my access database. I was able to display data from my database to the datagridview but it is not filtered. The datagridview displays all the records on my database. I tried using query builder to execute sql select statements that will filter the data and this is where I'm stuck. Im using a variable as a parameter to the sql statement and I dont know what syntax to use in Query Builder. I tried to use @varname, '" & varname & "', and ?varname but they are not recognized. Can someone pls tell me the correct syntax? Thanks!

Use RowFilter property of DataView,

Dim Adp as New OledbDataAdapter("select * from tableName","Connection_String")
 Dim Dt as new DataTable
 
 Adp.Fill(Dt)
 Dim Dv as DataView
 Dv=Dt.DefaultView

 DataGridView1.DataSource=Dv
 Dv.RowFilter="ColName='Value'"
 'OR
 Dv.RowFilter='ColName1>=10 and ColName1<=30 or ColName2 like 'A%'"

Use RowFilter property of DataView,

Dim Adp as New OledbDataAdapter("select * from tableName","Connection_String")
 Dim Dt as new DataTable
 
 Adp.Fill(Dt)
 Dim Dv as DataView
 Dv=Dt.DefaultView

 DataGridView1.DataSource=Dv
 Dv.RowFilter="ColName='Value'"
 'OR
 Dv.RowFilter='ColName1>=10 and ColName1<=30 or ColName2 like 'A%'"

Thanks for the code, but I was just wondering if where will i put this code. To a form?a button?or a datagrid?

Show us your code please. Use bb code tags; read announcement - about bb code tag.

I've already put it in my code, and it seems to be working well. Thanks for your help!I hope I could help other people as well.

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