one has the subteam for example if you click the 1st combo box, the items would be
what i want to happen is that if i chose A1 only the members of team A1 would appear in my combo box2. and by that, you need an sql statement. but how do i code that? can someone help me?
In the selectedIndexChanged event of the first combo box you determine the selected index and include that into your SQL string.
string selectedTeam = comboBox1.SelectedItem.ToString();
string sql = "SELECT * FROM yourTable WHERE team = ?selectedTeam;";
cmd.CommandText = sql;
cmd.Parameters["?selectedTeam"].Value = selectedTeam;
I'm assuming you have a command object called cmd of course. After that open your connection, execute the command, catch the results in a dataTable or reader and import into the second comboBox. I have made so assumptions about your database table design too of course.
Thats c# (i'm always making that mistake)...
I'll post something more complete in a couple of hours. I'm going to assume your database is set up with a table of teams, a table of players and a table that links the two. I hope thats accurate.
Dim str_query As String = "select * from tableName where Field=" & Combo1.Text &"
cmd = New SqlCommand(str_query, Conn)
dr = cmd.ExecuteReader
Do While dr.Read()
I used SqlCe as the database if using .mdf db then change the variables to SqlCommand instead of SqlCeCommand and so on.
Imports System.Data.SqlClient 'if using .mdf
Public Class Form2
Private Const ConnectionString As String = "Your Connection String"
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If TypeOf ComboBox1.SelectedItem Is String Then
Dim Connection As New SqlCeConnection(ConnectionString)
Dim Command As SqlCeCommand = Connection.CreateCommand
Dim Reader As SqlCeDataReader = Nothing
Command.CommandText = "Select *" & vbCrLf & _
"From finaltickettable" & vbCrLf & _
"Where Subteam = @SubTeam"
Reader = Command.ExecuteReader
Do While Reader.Read
Catch ex As Exception
'dispose may not be available with sqldatareader
If Reader IsNot Nothing Then Reader.Dispose()
hi Unhnd Exception! its fixed but i still got one problem though. in my record, name jake held 3 tickets so he has 3 records in my database. he is in team A4. whenever i choose A4 his name appears thrice. how will i fix that?
You need to change your Select statement to add Distinct