09-02-2012, 08:44 PM
Hey guys,
I'm using the following code to pull data from two tables in my MySQL database. Currently, the data is being loaded directly to the TextBox controls on my form.
What I want to do is this, but don't know how:
HERE'S MY CURRENT CODE:
[code2=vbnet]Public Sub InitiateQuery()
Try
If TextBoxAccount.Text = "" Then
MessageBox.Show("Sorry, you must enter an ACCOUNT# before proceeding!")
TextBoxAccount.Focus()
Else
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=hello;Password=123##123;Database=accounting")
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("SELECT * FROM customer a INNER JOIN cc_master b ON a.accountNumber = b.customer_accountNumber WHERE a.accountNumber = " & TextBoxAccount.Text, dbConn)
Dim myDatatable As New DataTable
dbAdapter.Fill(myDatatable)
If myDatatable.Rows.Count > 0 Then
'MessageBox.Show("Customer Account Found!")
TextBoxLastName.Text = myDatatable.Rows(0).Item("nameLAST")
TextBoxFirstName.Text = myDatatable.Rows(0).Item("nameFIRST")
TextBoxSalutation.Text = myDatatable.Rows(0).Item("nameSALUTATION")
TextBoxCompanyName.Text = myDatatable.Rows(0).Item("nameCOMPANY")
TextBoxCard.Text = myDatatable.Rows(0).Item("ccNumber")
TextBoxCardType.Text = myDatatable.Rows(0).Item("ccType")
TextBoxExpireMonth.Text = myDatatable.Rows(0).Item("ccExpireMonth")
TextBoxExpireYear.Text = myDatatable.Rows(0).Item("ccExpireYear")
TextBoxCVV2.Text = myDatatable.Rows(0).Item("ccCode")
TextBoxZip.Text = myDatatable.Rows(0).Item("ccZipcode")
Else
MessageBox.Show("No Credit/Debit Card on file for this customer! Please try again!")
TextBoxAccount.Focus()
End If
dbConn.Close()
End If
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.")
End Try
End Sub[/code2]
Thanks to you Brandon, I was able to learn how to do this query following your video tutorials.
I'm using the following code to pull data from two tables in my MySQL database. Currently, the data is being loaded directly to the TextBox controls on my form.
What I want to do is this, but don't know how:
- 1. Load only Credit Card Number (ccNumber) into a ComboBox
- 2. Load the data into the TextBox controls only after the Credit Card loaded earlier has been selected from the ComboBox
HERE'S MY CURRENT CODE:
[code2=vbnet]Public Sub InitiateQuery()
Try
If TextBoxAccount.Text = "" Then
MessageBox.Show("Sorry, you must enter an ACCOUNT# before proceeding!")
TextBoxAccount.Focus()
Else
dbConn = New MySqlConnection("Server=" & FormLogin.ComboBoxServerIP.SelectedItem & ";Port=3306;Uid=hello;Password=123##123;Database=accounting")
If dbConn.State = ConnectionState.Open Then
dbConn.Close()
End If
dbConn.Open()
Dim dbAdapter As New MySqlDataAdapter("SELECT * FROM customer a INNER JOIN cc_master b ON a.accountNumber = b.customer_accountNumber WHERE a.accountNumber = " & TextBoxAccount.Text, dbConn)
Dim myDatatable As New DataTable
dbAdapter.Fill(myDatatable)
If myDatatable.Rows.Count > 0 Then
'MessageBox.Show("Customer Account Found!")
TextBoxLastName.Text = myDatatable.Rows(0).Item("nameLAST")
TextBoxFirstName.Text = myDatatable.Rows(0).Item("nameFIRST")
TextBoxSalutation.Text = myDatatable.Rows(0).Item("nameSALUTATION")
TextBoxCompanyName.Text = myDatatable.Rows(0).Item("nameCOMPANY")
TextBoxCard.Text = myDatatable.Rows(0).Item("ccNumber")
TextBoxCardType.Text = myDatatable.Rows(0).Item("ccType")
TextBoxExpireMonth.Text = myDatatable.Rows(0).Item("ccExpireMonth")
TextBoxExpireYear.Text = myDatatable.Rows(0).Item("ccExpireYear")
TextBoxCVV2.Text = myDatatable.Rows(0).Item("ccCode")
TextBoxZip.Text = myDatatable.Rows(0).Item("ccZipcode")
Else
MessageBox.Show("No Credit/Debit Card on file for this customer! Please try again!")
TextBoxAccount.Focus()
End If
dbConn.Close()
End If
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.")
End Try
End Sub[/code2]
Thanks to you Brandon, I was able to learn how to do this query following your video tutorials.
//Kismet