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
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?Code: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
Last edited by v0id; 08-17-2007 at 10:36 PM. Reason: Added code-tags.
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:
Currently, your SQL is loading all games and not excluding other system ID games.Code:"SELECT GameID, GameName, SystemID, Note " & _ "WHERE SystemID=YourSystemIDVariable From GameList ORDER BY GameName"
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks