Complex Databinding接受Ilist或IlistSource作为数据源 [英] Complex Databinding accepts as a datasource either an Ilist or an IlistSource

查看:237
本文介绍了Complex Databinding接受Ilist或IlistSource作为数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里有Pros,



我的问题和疑问:

如何从表中加载数据并在checkedlistbox上显示?我只是编写了代码,但未能实现这一点而且我遇到了错误。



优点在那里请帮助我并给出指导,我不知道错误显示下面:!!!!



错误消息msg =复杂数据绑定接受Ilist或IlistSource作为数据源



 尝试 
Dim myCMD As SqlClient.SqlCommand = SqlClient.SqlCommand( SELECT deno,dename,cno FROM departmenttbl WHERE cno IS NULL,connection)
如果连接.State = ConnectionState.Closed 然后
connection.Open()
结束 < span class =code-keyword>如果

Dim myDataReader As SqlClient.SqlDataReader = myCMD.ExecuteReader
如果 myD ataReader.HasRows 然后
CheckedListBox1.DataSource = myDataReader
CheckedListBox1.DisplayMember = dename
CheckedListBox1.ValueMember = deno
结束 如果
Catch ex As 异常
MsgBox(ex.Message)
结束 尝试
connection.Close()

解决方案

< blockquote>

  Dim  dt1  As   DataTable 
Dim dlebgrab As 字符串 = SELECT * FROM departmenttbl
Dim cmd as OleDbCommand(dlebgrab,连接)
Dim adtp As < span class =code-keyword>新 OleDbDataAdapter(cmd)
adtp.SelectCommand = cmd
adtp.Fill(dt1)

CheckedListBox1.DisplayMember = < span class =code-string> dename
CheckedListBox1.ValueMember = deno
CheckedListBox1.DataSource = dt1


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

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()

解决方案

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


这篇关于Complex Databinding接受Ilist或IlistSource作为数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆