Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 28-Jun-15 23:35pm
v3
Comments
Kats2512 29-Jun-15 6:04am    
please provide code
Member 11644196 29-Jun-15 6:41am    
Dim dtPersons As DataTable
For Each dRow As DataRow In dtPersons.Rows
CheckedListBox1.Items.Add(dRow.Item("Firstname"))
Next

This is all i have, im not sure how to do this

1 solution

VB
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


VB
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
 
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