none
Issues displaying data in a checkedlistbox RRS feed

  • Question

  • Hi All,

    This should be rather straight forward, but I'm having issues displaying data in a checklistbox using the following:

    Dim dsn As String = "server=MySQLSERVER2012;database=MyDatabase;uid=UserName;pwd=UserPassword"
    Dim conn As SqlConnection = New SqlConnection(dsn)
    Dim cmd As SqlCommand = New SqlCommand
    conn.Open()
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "[usp_L_AccountsReportFields_SEL]"
    cmd.Connection = conn
    Dim adapter As New SqlDataAdapter(cmd)
    Dim ds As New DataSet
    adapter.Fill(ds, "L_AccountsReportFields_SEL")
    conn.Close()
    
    clbAccountsFields.DataSource = ds.Tables("L_AccountsReportFields")
    clbAccountsFields.ValueMember = "AccountsReportFieldsListPKID"
    clbAccountsFields.DisplayMember = "ReportsFieldList"
    
    clbAccountsFields.CheckOnClick = True
    clbAccountsFields.MultiColumn = True

    I get no errors, just no data in the checkedlistbox.

    Would someone please show me what I've not done correctly.

    Thank you.


    Onward through the fog......

    Sunday, November 26, 2017 4:29 PM

Answers

  • What we cannot see is if you use the rigth string names, be aware that those are for System Data case sensitive. 

    By the way, you use a lot of code, it looks much as we see often on Internet a kind of VB7.0 (not even 7.1) style. 

    It can also be this. 

            Dim ds As New DataSet
            Using conn As New SqlConnection("server=MySQLSERVER2012;database=MyDatabase;uid=UserName;pwd=UserPassword")
                Using cmd As New SqlCommand With {.CommandType = CommandType.StoredProcedure, .CommandText = "[usp_L_AccountsReportFields_SEL]", .Connection = conn}
                    conn.Open()
                    Dim adapter As New SqlDataAdapter(cmd)
                    adapter.Fill(ds, "L_AccountsReportFields_SEL")
                End Using
            End Using
            clbAccountsFields.DataSource = ds.Tables("L_AccountsReportFields")
            clbAccountsFields.ValueMember = "AccountsReportFieldsListPKID"
            clbAccountsFields.DisplayMember = "ReportsFieldList"
            clbAccountsFields.CheckOnClick = True
            clbAccountsFields.MultiColumn = True


    Success
    Cor


    • Edited by Cor Ligthert Sunday, November 26, 2017 4:44 PM
    • Marked as answer by g-dawg Monday, November 27, 2017 1:43 AM
    Sunday, November 26, 2017 4:43 PM

All replies

  • What we cannot see is if you use the rigth string names, be aware that those are for System Data case sensitive. 

    By the way, you use a lot of code, it looks much as we see often on Internet a kind of VB7.0 (not even 7.1) style. 

    It can also be this. 

            Dim ds As New DataSet
            Using conn As New SqlConnection("server=MySQLSERVER2012;database=MyDatabase;uid=UserName;pwd=UserPassword")
                Using cmd As New SqlCommand With {.CommandType = CommandType.StoredProcedure, .CommandText = "[usp_L_AccountsReportFields_SEL]", .Connection = conn}
                    conn.Open()
                    Dim adapter As New SqlDataAdapter(cmd)
                    adapter.Fill(ds, "L_AccountsReportFields_SEL")
                End Using
            End Using
            clbAccountsFields.DataSource = ds.Tables("L_AccountsReportFields")
            clbAccountsFields.ValueMember = "AccountsReportFieldsListPKID"
            clbAccountsFields.DisplayMember = "ReportsFieldList"
            clbAccountsFields.CheckOnClick = True
            clbAccountsFields.MultiColumn = True


    Success
    Cor


    • Edited by Cor Ligthert Sunday, November 26, 2017 4:44 PM
    • Marked as answer by g-dawg Monday, November 27, 2017 1:43 AM
    Sunday, November 26, 2017 4:43 PM
  • I have a MSDN code sample "VB.NET Working with ChecledListBox and SQL-Server". Some of the samples do updates to the database while other do reads only.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, November 26, 2017 4:51 PM
    Moderator
  • Try this modification too:

       clbAccountsFields.DataSource = ds.Tables("L_AccountsReportFields_SEL")

    Sunday, November 26, 2017 8:02 PM
  • Thank you Cor,

    I did find a misspelled table name in one of my stored procedures. Don't know how many times I've looked at the code just knowing "everything was correct".

    And yes, I can get a little wordy on code. Thanks for showing me your way.

    gdr


    Onward through the fog......

    Monday, November 27, 2017 1:40 AM
  • Hi Karen,

    Thanks for your answer. The added code "should" help me down the road, especially when I try to get the checked items out into a string for my next steps.

    gdr


    Onward through the fog......

    Monday, November 27, 2017 1:43 AM