I am writing a school project in VB005 and am trying to hook up a second combo box that gets its information of what to display from the first combo box. My application is where a student takes a "test" but they can choose what instructor they want in the first combo box. From there, they choose from a test of what each instructor offers in the second combo box. As of right now, my first combo box works great and my second combo box has nothing in it. Just a note, when I debug, it shows my iUserID value as 0. Any help on this is greatly appreciated.
Main code:
Class Code:
Main code:
VB.NET:
dsInstructor = oInstructor.GetData(m_UserID)
dsUser = oUser.GetData
cmgrInstructor = CType(Me.BindingContext(dsInstructor.Tables(0)), CurrencyManager)
For x = 0 To dsUser.Tables(0).Rows.Count
If dsUser.Tables(0).Rows(x).Item(0) = iStudentID Then
txtWelcome.Text = dsUser.Tables(0).Rows(x).Item("FullName")
Exit For
End If
Next
cboInstructor.DataSource = dsInstructor.Tables(0)
cboInstructor.DisplayMember = "FullName"
cboInstructor.ValueMember = "UserID"
dsTest = oTest.GetData(m_Test)
cmgrTest = CType(Me.BindingContext(dsTest.Tables(0)), CurrencyManager)
cboTest.DataSource = dsTest.Tables(0)
cboTest.DisplayMember = "TestName"
cboTest.ValueMember = "TestID"
VB.NET:
Private Function CreateDASelectCommand() As OleDb.OleDbCommand
Dim sSQL As String 'string with SQL
Dim cmd As New OleDb.OleDbCommand(sSQL, m_oCn) 'command object
'---------------------------------------------------------
'--- Set up the SELECT Command
'---------------------------------------------------------
sSQL = "select * from tblTest" 'SQL to use
'sSQL &= " where UserID = " & sUserID
cmd.CommandText = sSQL
cmd.CommandType = CommandType.Text 'this is SQL rather than a stored procedure
Return cmd 'return the full command
End Function
Public Function GetData(ByVal iUserID As Integer) As DataSet
Dim sSQLOrig As String = "" 'The original SQL used for all records
Try
''--- Create a new DataSet
sSQLOrig = m_oDA.SelectCommand.CommandText
m_oDA.SelectCommand.CommandText &= " where UserID = " & iUserID.ToString
'm_oDA.SelectCommand.CommandText &= " and TestID = " & sTestID.ToString
m_oCn.Open()
m_oDS = New DataSet
''--- Fill the DataSet with the Customers
m_oDA.Fill(m_oDS, m_sClassName)
m_oCn.Close()
''//--- Return the DataSet
Return m_oDS
Catch ex As Exception
Throw ex
Finally
'reset SQL back to generic 'Grab Everything'
m_oDA.SelectCommand.CommandText = sSQLOrig
End Try
End Function
Last edited: