Search database in datagridview using combobox at VB6?
-
Hi. I'm sorry I'm new to this. I am creating a simple information system and in my search form I want to have a combobox where users can select like "By: ID Number" or "By: Name" then it will also have a textbox to input names or id and it will display on datagridview. do you have any idea or some sample code? I hope it made sense. any help will be greatly appreciated. :)
-
Answer:
' Sample source code http://www.andronscomputing.com/getfile.php?resource=download/databaseSearch.zip Private gblRecordSet Private adodbConnection Private Sub Command1_Click() Dim tRecordset If LCase(Combo1.Text) = "by id" Then query = "Select Name, PhoneNumber, PersonID from Persons where PersonID = " & Text1.Text & "" Else query = "Select Name, PhoneNumber, PersonID from Persons where Name like '%" & Text1.Text & "%'" End If Set DataGrid1.DataSource = adodbConnection.execute(query) End Sub Private Sub Command2_Click() Set gblRecordSet = adodbConnection.execute("Select Name, PhoneNumber, PersonID from Persons") Set DataGrid1.DataSource = gblRecordSet End Sub Private Sub Form_Load() Combo1.addItem("By ID") Combo1.addItem("By Name") Set adodbConnection = CreateObject("ADODB.Connection") adodbConnection.CursorLocation = 3 adodbConnection.open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=dbSearch.mdb" Set gblRecordSet = adodbConnection.execute("Select Name, PhoneNumber, PersonID from Persons") Set DataGrid1.DataSource = gblRecordSet End Sub
Kendall at Yahoo! Answers Visit the source
Other answers
omid
Related Q & A:
- How To Search People Using Phone Number?Best solution by Yahoo! Answers
- How to connect to a Pervasive Database using javascript?Best solution by Stack Overflow
- How to store an image in database using MySQL?Best solution by stackoverflow.com
- how can I listen for database changes using java?Best solution by Stack Overflow
- How to save from DatagridView to Database VB.NET?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.