Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I fill my form with MySQL data based on Combobox?
#1
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]
//Kismet


Messages In This Thread
How do I fill my form with MySQL data based on Combobox? - by kismetgerald - 09-30-2012, 06:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I read a link from mysql databse??? mnxford 9 33,028 04-12-2013, 06:27 PM
Last Post: brandonio21
  I am getting problem with brandonio's registration form... mnxford 1 9,167 03-27-2013, 10:55 AM
Last Post: mnxford
  i am getting a problem with brandonio's login form mnxford 1 9,096 03-27-2013, 10:55 AM
Last Post: mnxford
  How do I use Listview to delete MySQL DB records kismetgerald 10 33,848 11-28-2012, 05:19 PM
Last Post: brandonio21
  [SOLVED] MySQL Update Query - What am I doing wrong? kismetgerald 11 43,301 10-18-2012, 07:16 PM
Last Post: brandonio21
  Loading DB data into Combobox then populate TextBox Controls kismetgerald 0 5,708 09-02-2012, 08:44 PM
Last Post: kismetgerald
  Help with creating an INSERT statement using MySQL kismetgerald 4 16,751 08-30-2012, 03:03 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 29,043 08-13-2012, 08:58 PM
Last Post: brandonio21
  getting a file name form a save dialoge zmanalpha 3 14,108 08-04-2012, 03:15 PM
Last Post: brandonio21
  MySql Database Queries in VB.Net Moldraxian 6 22,372 07-26-2012, 03:44 PM
Last Post: Moldraxian

Forum Jump:


Users browsing this thread: 1 Guest(s)