如何在Sql表中的列中将项目加载到Checkedlistbox中。 [英] How Do I Load Items In To A Checkedlistbox From A Column In Sql Table.

查看:75
本文介绍了如何在Sql表中的列中将项目加载到Checkedlistbox中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有一个表格,其中包含姓名,姓氏和组号。我需要使用SqlDataReader并使用此条件在第一列(Firstname)上填充CheckedListBox和数据。

Lets say there is a table with colums Firstname, Lastname and Groupnumber. I need to fill a CheckedListBox with the data on the first column(Firstname)using SqlDataReader and also with this condition;

WHERE  Groupnumber = '" & TextBox1.Text.Trim & "'"



谢谢。


Thank you.

推荐答案

Public Function SelectFromDatabase(ByVal SelectStatement As String) As DataTable
       Dim Dt As New DataTable()
       'remember to change 'ConnectionString' to your an your own connection string
       Dim SQLDA As New SqlClient.SqlDataAdapter(SelectStatement, "ConnectionString")
       SQLDA.Fill(Dt)
       Return Dt
   End Function







Dim dtPersons As DataTable
        dtPersons = SelectFromDatabase("select firstname, lastname, Groupnumber from Table WHERE  Groupnumber = '" & TextBox1.Text.Trim & "'")
        For Each dRow As DataRow In dtPersons.Rows
            CheckedListBox1.Items.Add(dRow.Item("Firstname"))
        Next


这篇关于如何在Sql表中的列中将项目加载到Checkedlistbox中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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