Click here to Skip to main content
16,007,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There Pros out there,

My question and problem:
how to load data from table and show on checkedlistbox? i simply wrote the codes but fail to achieve this and i faced error.

Pros out there please help me and give a guide, i got no idea on the error show below:!!!!

error msg = Complex Databinding accepts as a datasource either an Ilist or an IlistSource

VB
Try
            Dim myCMD As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT deno, dename, cno FROM departmenttbl WHERE cno IS NULL", connection)
            If connection.State = ConnectionState.Closed Then
                connection.Open()
            End If

            Dim myDataReader As SqlClient.SqlDataReader = myCMD.ExecuteReader
            If myDataReader.HasRows Then
                CheckedListBox1.DataSource = myDataReader
                CheckedListBox1.DisplayMember = "dename"
                CheckedListBox1.ValueMember = "deno"
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        connection.Close()
Posted

1 solution

VB
Dim dt1 As New DataTable
Dim dlebgrab As String = "SELECT * FROM departmenttbl"
Dim cmd As New OleDbCommand(dlebgrab, connection)
Dim adtp As New OleDbDataAdapter(cmd)
adtp.SelectCommand = cmd
adtp.Fill(dt1)

CheckedListBox1.DisplayMember = "dename"
CheckedListBox1.ValueMember = "deno"
CheckedListBox1.DataSource = dt1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900