Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

help with comboboxes and SQL in VB.Net

VB.NET combobox

  • Please log in to reply
1 reply to this topic

#1 shazo

shazo

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 17 August 2007 - 11:58 AM

Some one asked me to write a program for them to store a list of all the video games and systems they own. I'm trying to set it up so they select the system in a combo box and in another combo box it will list allthe games for that system. for example they select dreamcast out of the combo box it will list all the dreamcast games they own. Then if they select xbox it will list all the xbox games and for ps2 all the ps2 games. so the games combo box will be reloaded when a new system is selected so that the list only shows games for that system. I'm trying to do this in code and not by the properties. I am using VB.Net and SQL both are express. This is the code I have as of now

Imports System.Data 
Imports System.Data.SqlClient 
Imports System.configuration 
Public Class MainForm 
Private IsLoading As Boolean 

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
IsLoading = True 
Dim cnString As String = _ 
ConfigurationManager.ConnectionStrings("GameListConnection").ConnectionString 
Dim strSelect As String = _ 
"SELECT SystemID, SystemName " & _ 
"From SystemList ORDER BY SystemName" 

Dim daSystems As New SqlDataAdapter(strSelect, cnString) 
Dim dsSystems As New DataSet 
daSystems.Fill(dsSystems, "SystemList") 

cboSystem.DataSource = dsSystems.Tables("SystemList") 
cboSystem.DisplayMember = "SystemName" 
cboSystem.ValueMember = "SystemID" 

Call BindClassListBox() 
IsLoading = False 

End Sub 

Private Sub cboSystem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboSystem.SelectedIndexChanged 
If Not IsLoading Then 
Call BindClassListBox() 
End If 
End Sub 

Private Sub BindClassListBox() 

Dim cnString As String = _ 
ConfigurationManager.ConnectionStrings _ 
("GameListConnection").ConnectionString 
Dim strSelect2 As String = _ 
"SELECT GameID, GameName, SystemID, Note " & _ 
"From GameList ORDER BY GameName" 

Dim daGames As New SqlDataAdapter(strSelect2, cnString) 
Dim dsGames As New DataSet 
daGames.Fill(dsGames, "GameList") 

cboGame.DataSource = dsGames.Tables("GameList") 
cboGame.DisplayMember = "GameName" 
cboGame.ValueMember = "GameID" 
End Sub 
End Class 

The combo boxes load all of it fine now but they load every game no mater what system is selected. Any one know what I need to do?
  • 0

#2 Lop

Lop

    Speaks fluent binary

  • Just Joined
  • PipPipPipPipPipPipPip
  • 1112 posts

Posted 18 August 2007 - 04:55 AM

I do not know how your table structure is setup but I can see the problem. I hope I can explain it - here goes:

In your selectedindexchange function you select the games associated with the system *except* you have no where clause in your SQL. You need to get the selected index (either system name or system ID) and add add a where clause:

"SELECT GameID, GameName, SystemID, Note " & _ 
"WHERE SystemID=YourSystemIDVariable From GameList ORDER BY GameName" 

Currently, your SQL is loading all games and not excluding other system ID games.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download