textbox filter query

simran

Member
Joined
Jul 7, 2006
Messages
8
Programming Experience
Beginner
Hi Kulrom

Once again I need your help.
I want to use data grid in my project. If I use Data Grid then it will display all the records from the table. But My requirement is somewhat different.

E.g. I have a databse in access-" db1"
It is having 1 table "Table1". This table is having 4 fields : - ID, name, role, address
The "name" field is having 4 records : John, harry, tarun, harry.

Here "harry" is stored twice.

I want to include a searching form containing textbox where user has to write the name of the person whose records he/she want to search & click on "SEARCH" button. I don't want to do this with "ID".

Now I want that when the user clicks on search button after writing the name of the person, all his records must be displayed in data grid not in textboxes. I don't want to display all the records from the table but only those records that are related to that name which is entered in textbox.

E.g. As written above "harry" is stored twice in the "table 1" of database "db1". When user writes "harry" in textbox, all the records related to "harry" in that table must be displayed in data grid.

I hope that you can solve this problem. I shall be very grateful to you. Once again Thanks a lot for your previous response.


(SIMRANJIT SINGH)
 
You'll need a datatable to fill with the results from the following query...

' Btn Search Click

VB.NET:
Dim Da as new OleDbDataAdapter
Dim DBCom as new oleDbCommand("SELECT * FROM Table1 WHERE name = ?", your connection)
DBCom.parameters.add("@Name",oledbype.varwchar,255,"name").Value = TxtSearch.text
 
Da.SelectCommand = DBCom
Da.Fill(Your DataTable)
 
Your DataGrid.DataSource = Your DataTable

I hope thats reasonably clear, if you need any further explanation let me know.
 
Please post unrelated inquiries in new threads, thank you simran. Post moved, topic set to "textbox filter query".
 
Agreed, repeated round trips to the database should be avoided as far as possible. A related note, if you are not planning to modify this data then you may also want to look into the DataReader. There are lots on articles on the web on this topic. Google for 'VB.Net - DataReader'
 
Back
Top