Click here to Skip to main content
15,884,720 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
who can i get items from database to check list box?
Posted
Comments
King Fisher 3-May-14 6:50am    
not clear

read the datafrom database, for example you can get DataTable
C#
myCheckedListBox.DataSource = fillDataTable();
myCheckedListBox.DisplayMember = "DisplayColumnName";
myCheckedListBox.ValueMember = "valueColumnName";

thst's it :)
C#
public DataTable fillDataTable()
{
    using(SqlConnection sqlConn = new SqlConnection(conSTR))
    using(SqlCommand cmd = new SqlCommand("select DisplayColumnName,valueColumnName from MyTable" , sqlConn))
    {
        sqlConn.Open();
        DataTable dt = new DataTable();
        dt.Load(cmd.ExecuteReader());
        return dt;
    }
}
 
Share this answer
 
v3

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