09-30-2012, 06:28 PM
Hey guys/gals,
So with the help of fellow members @ stackoverflow.com, I've been able to retrieve some data from my MySQL database and bind the results to a Combobox (ComboBoxCard) using the code below.
Now I would like to display the results of my query in some controls on my form (5 Textboxes, 1 Combobox, and 2 DateTimePickers) based on the selected value of ComboBoxCard. How do I do this?
The primary goal of this particular form in my application is to allow the user to update a customer's credit card information. Sometimes, a customer may have more than 1 card on file - which is why I needed a mechanism to display all cards on file and allow the user to use the Combobox to select which card to update. So, if there's a better way to do this please do not hesitate to suggest.
Thanks.
HERE'S MY CODE:
[code2=vbnet]Private Sub RetrieveMySQLdata()
Try
'FOR MySQL DATABASE USE
Dim dbQuery As String = ""
Dim dbCmd As New MySqlCommand
Dim dbAdapter As New MySqlDataAdapter
Dim dbTable As New DataTable
If dbConn.State = ConnectionState.Closed Then
dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
dbConn.Open()
End If
dbQuery = "SELECT *" & _
"FROM cc_master INNER JOIN customer ON customer.accountNumber = cc_master.customer_accountNumber " & _
"WHERE customer.accountNumber = '" & TextBoxAccount.Text & "'"
With dbCmd
.CommandText = dbQuery
.Connection = dbConn
End With
With dbAdapter
.SelectCommand = dbCmd
.Fill(dbtable)
End With
ComboBoxCard.DataSource = dbTable
ComboBoxCard.ValueMember = "ccNumber"
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
Finally
dbConn.Close()
End Try
End Sub[/code2]
So with the help of fellow members @ stackoverflow.com, I've been able to retrieve some data from my MySQL database and bind the results to a Combobox (ComboBoxCard) using the code below.
Now I would like to display the results of my query in some controls on my form (5 Textboxes, 1 Combobox, and 2 DateTimePickers) based on the selected value of ComboBoxCard. How do I do this?
The primary goal of this particular form in my application is to allow the user to update a customer's credit card information. Sometimes, a customer may have more than 1 card on file - which is why I needed a mechanism to display all cards on file and allow the user to use the Combobox to select which card to update. So, if there's a better way to do this please do not hesitate to suggest.
Thanks.
HERE'S MY CODE:
[code2=vbnet]Private Sub RetrieveMySQLdata()
Try
'FOR MySQL DATABASE USE
Dim dbQuery As String = ""
Dim dbCmd As New MySqlCommand
Dim dbAdapter As New MySqlDataAdapter
Dim dbTable As New DataTable
If dbConn.State = ConnectionState.Closed Then
dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
dbConn.Open()
End If
dbQuery = "SELECT *" & _
"FROM cc_master INNER JOIN customer ON customer.accountNumber = cc_master.customer_accountNumber " & _
"WHERE customer.accountNumber = '" & TextBoxAccount.Text & "'"
With dbCmd
.CommandText = dbQuery
.Connection = dbConn
End With
With dbAdapter
.SelectCommand = dbCmd
.Fill(dbtable)
End With
ComboBoxCard.DataSource = dbTable
ComboBoxCard.ValueMember = "ccNumber"
Catch ex As Exception
MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
Finally
dbConn.Close()
End Try
End Sub[/code2]
//Kismet