Question Not getting any value in cboSubCategory?

VS2013LEARNER

New member
Joined
May 5, 2022
Messages
2
Programming Experience
Beginner
The following is the code but it is not showing any value though the data is available in MS Access Database.

VB.NET:
Private Sub cboMainCategory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboMainCategory.SelectedIndexChanged
        txtMainCategory.Text = cboMainCategory.Text
        cboSubCategory.DataSource = Nothing
        cboSubCategory.Items.Clear()

        Call cboLoadSubCategory()
        txtSubCategory.Select()
    End Sub
    Public Function cboLoadSubCategory()
        If txtMainCategory.Text = "TILING" Then
            Dim StrSql As String = "Select Category from SubCategories3Table"

        ElseIf txtMainCategory.Text = "ELECTRIC CONNECTION" Then
            Dim StrSql As String = "Select Category from SubCategories4Table"

        ElseIf txtMainCategory.Text = "WATER CONNECTION" Then
            Dim StrSql As String = "Select Category from SubCategories5Table"

        Else
            Dim StrSql As String = "Select Category from SubCategories1Table"

            Dim dt As New DataTable
            If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Return 0
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            cboSubCategory.ValueMember = "Category"
            cboSubCategory.DataSource = ds.Tables(0)
            If ds.Tables(0).Rows.Count > 0 Then
                cboSubCategory.SelectedIndex = 0
            End If
        End If

        Return True
    End Function
 

VS2013LEARNER

New member
Joined
May 5, 2022
Messages
2
Programming Experience
Beginner
Getting no error but won't show available text in the Combo Box. The following code is also the same. No error no data.
VB.NET:
Public Function cboLoadSubCategory()
        Dim StrSql As String
        Dim dt As New DataTable
        Dim ds As New DataSet

        If cboMainCategory.Text = "TILING" Then
            StrSql = "Select Category from SubCategories3Table"
            If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Return 0
            ds.Tables.Add(dt)
            cboSubCategory.ValueMember = "Category"
            cboSubCategory.DataSource = ds.Tables(0)
            If ds.Tables(0).Rows.Count > 0 Then
                cboSubCategory.SelectedIndex = 0

            ElseIf cboMainCategory.Text = "ELECTRIC CONNECTION" Then
                StrSql = "Select Category from SubCategories4Table"

                If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Return 0
                ds.Tables.Add(dt)
                cboSubCategory.ValueMember = "Category"
                cboSubCategory.DataSource = ds.Tables(0)
                If ds.Tables(0).Rows.Count > 0 Then
                    cboSubCategory.SelectedIndex = 0

                ElseIf cboMainCategory.Text = "WATER CONNECTION" Then
                    StrSql = "Select Category from SubCategories5Table"

                    If Not DAL.ExecuteSql(dt, StrSql, Msg) Then MsgBox(Msg, MsgBoxStyle.Exclamation, "Error") : Return 0
                    ds.Tables.Add(dt)
                    cboSubCategory.ValueMember = "Category"
                    cboSubCategory.DataSource = ds.Tables(0)
                    If ds.Tables(0).Rows.Count > 0 Then
                        cboSubCategory.SelectedIndex = 0
                    End If
                End If
            End If
        End If

        'cboSubCategory.SelectedIndex = 0
        Return True
    End Function
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,717
Location
Sydney, Australia
Programming Experience
10+
Firstly, why are you setting the ValueMember but not the DisplayMember? Secondly, have you actually debugged that code, i.e. set a breakpoint and stepped through the code line by line to evaluate relevant variables and other expressions at each step? I'm confident that the answer to that is "no". You're not just a user. You're the developer. You don't test the application just by using it. You use the development tools you have available to examine its inner workings in detail. Use the debugger is VS to work out what the code is doing and exactly where it's not doing what you expect. It will be obvious why no data is being displayed in both cases if you actually use the debugger.
 

Latest posts

Top Bottom