Greetings all,
First things first, i'm new here so Hi! I have dabbled in a few programming/scripting languages but generally considermyself to be a beginner.
I am trying to make a vb.net application that will form the front end of a mysql database.
I have three combo boxes which I wish to use to narrow down the choices in the adjacent combo box. For example combobox1 will list all the geographical locations in the database, and combo box 2 should then list all the venues that are in the chosen location. combo box 3 will narrow down the selection further.
My question is two fold:
Firstly here is the code I have managed to cobble together so far:
The code above connects to the database and populates combo box 1, but when i duplicated the code and changed the variable names for combo box 2 it doesnt work. Where am I going wrong?
The second part of my question ... how do I go about using the selected value from combo box 1 as part of the select statement in combobox 2? I want to be able to add an 'AND' clause to my sql statement for combobox 2 which is equal to the selected value for combo box 1 . I hope this makes sense.
Finally if I am doing anything stupid, or simply just writing with bad habbits or inefficiently I would always welcome any tips/suggestions to improve. Even if it seems like overstating the ovbious I really am a beginner with all this so I wont be offended!
I'm still trying to get my head around all this dataadapter stuff and generally the concept of classes and I dont yet fully grasp what stuff i have to duplicate and what stuff I can reuse.
Thanks in Advance,
DJ
First things first, i'm new here so Hi! I have dabbled in a few programming/scripting languages but generally considermyself to be a beginner.
I am trying to make a vb.net application that will form the front end of a mysql database.
I have three combo boxes which I wish to use to narrow down the choices in the adjacent combo box. For example combobox1 will list all the geographical locations in the database, and combo box 2 should then list all the venues that are in the chosen location. combo box 3 will narrow down the selection further.
My question is two fold:
Firstly here is the code I have managed to cobble together so far:
VB.NET:
Imports MySql.Data.MySqlClient 'Import MySQL Connection Object
Public Class Form1
Dim conn As MySqlConnection = New MySqlConnection()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'******* Connection String *****************
conn.ConnectionString = "server=localhost;" _
& "user id=root;" _
& "password='';" _
& "database=db"
Try
conn.Open()
Label1.Text = "Connection Opened Successfully"
conn.Close()
Catch myerror As MySqlException
Label1.Text = "Connection Failed:" & myerror.Message
Finally
conn.Dispose()
End Try
'*****************************************************************
'Populate 1st combo box
Dim strSQL As String = "SELECT DISTINCT Location FROM Academy ORDER BY Location ASC"
Dim da As New MySqlDataAdapter(strSQL, conn)
Dim ds As New DataSet
da.Fill(ds, "Academy")
With ComboBox1
.DataSource = ds.Tables("Academy")
.DisplayMember = "Location"
.ValueMember = "Academy_Key"
.SelectedIndex = 0
End With
'Populate 2nd combo box
Dim strSQL2 As String = "SELECT DISTINCT Venue FROM Academy ORDER BY Venue ASC"
Dim da2 As New MySqlDataAdapter(strSQL2, conn)
Dim ds2 As New DataSet
da2.Fill(ds2, "Venue")
With ComboBox2
.DataSource = ds2.Tables("Venue")
.DisplayMember = "Venue"
.ValueMember = "Venue_Key"
.SelectedIndex = 0
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
The code above connects to the database and populates combo box 1, but when i duplicated the code and changed the variable names for combo box 2 it doesnt work. Where am I going wrong?
The second part of my question ... how do I go about using the selected value from combo box 1 as part of the select statement in combobox 2? I want to be able to add an 'AND' clause to my sql statement for combobox 2 which is equal to the selected value for combo box 1 . I hope this makes sense.
Finally if I am doing anything stupid, or simply just writing with bad habbits or inefficiently I would always welcome any tips/suggestions to improve. Even if it seems like overstating the ovbious I really am a beginner with all this so I wont be offended!
I'm still trying to get my head around all this dataadapter stuff and generally the concept of classes and I dont yet fully grasp what stuff i have to duplicate and what stuff I can reuse.
Thanks in Advance,
DJ