Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I fill my form with MySQL data based on Combobox?
#7
Thanks for the bump, I completely forgot about this post.

Anyway, So, since the combobox contains a list of all of the credit card number that belong to a certain user, we are going to want to do something when the combobox's selected index is changed.

First, we are going to get the credit card's number and save it.

Then, we need to select all of the records from the cc_master table and fill in all of the controls. This is pretty simple to do, we just need to use a new MySQL Query and fill in the data
[code2=vbnet]Private Sub ComboBoxCard_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBoxCard.SelectedIndexChanged
Dim creditCardNumber As String = ComboBoxCard.SelectedItem.ToString

'Here we use a new MySQL call to fill in fields using the existing dbConn
'variable
Dim dbQuery As String = ""
Dim dbCmd As New MySqlCommand
Dim dbAdapter As New MySqlDataAdapter
Dim data As MySqlDataReader
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 WHERE ccNumber='" & creditCardNumber & "'"

With dbCmd
.CommandText = dbQuery
.Connection = dbConn
End With
With dbAdapter
.SelectCommand = dbCmd
End With
data = dbCmd.ExecuteReader()

While data.Read()
'Now we can deal with each individual data entry and you can put it into
'various controls
txtExpireMonth.Text = data(2).ToString
txtExpireYear.Text = data(3).ToString
txtCode.Text = data(4).ToString
txtZipCode.Text = data(5).ToString
txtType.Text = data(6).ToString
txtAuthorizedUseStart.Text = data(7).ToString
txtAuthorizedUseEnd.Text = data(8).ToString
End While

'Now we close are vars to save memory
data.Close()


End Sub[/code2]

If you have any questions or this doesn't work, feel free to ask.
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Re: How do I fill my form with MySQL data based on Combobox? - by brandonio21_phpbb3_import2 - 10-13-2012, 01:44 PM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)