Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,033 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,586 people online right now. Registration is fast and FREE... Join Now!




Second combo box will not display anything

 
Reply to this topicStart new topic

Second combo box will not display anything, Uses info from first combo box and dataset

mikjall77
25 Feb, 2008 - 01:50 AM
Post #1

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 46



Thanked: 1 times
My Contributions
I am writing an app in VB2005 where you can take a "test" from different instructors. After logging in, you can choose an instructor using a combo box and then choose a test from that instructor using a second combo box. As of now, I have 3 instructors with 5 tests each. I am able to display my instructor combo box correctly, but nothing is showing up in my test combo box. I am using MS Access and my table is named tblTest, with three columns named TestID, UserID, and TableName, with TestID being the primary key. As a sidenote, when I debug the program, my iUserID variable is giving me a value of 0. I'm not sure if I'm not coding it correctly, or if it's within my SQL statement. If you need more code or information, or a suggestion of how I can do this better, please let me know. Thank you very much in advance for any help you can give me.
Code from form where check boxes are located:
CODE
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"

Code from class:
CODE
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
        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_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

User is offlineProfile CardPM
+Quote Post

mikjall77
RE: Second Combo Box Will Not Display Anything
25 Feb, 2008 - 03:50 AM
Post #2

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 46



Thanked: 1 times
My Contributions
Nevermind, I got it working.

This post has been edited by mikjall77: 25 Feb, 2008 - 03:52 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month