How to cleanly update database from Datagridview?

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

Was this solution helpful to you?

Other answers

Related Q & A:

Just Added Q & A:

Find solution

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.