Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
//Create SQL strings
    string sql = "select *from DatabaseLogin where user_id='" + textBox2.Text + "'";

    using (OleDbConnection dbConnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\MIS SYSTEM\AniPharmic\AniPharmic\MedicalDb.accdb;Jet OLEDB:Database Password="))
    {
        //dbAdapter = new OleDbDataAdapter(sql, dbConnection); //You dont need it
        //dataTable = new DataTable(); //don't need it
        dbConnection.Open();
        using (OleDbCommand oCommand = new OleDbCommand(sql, dbConnection))
        {
            using (OleDbDataReader dbReader = oCommand.ExecuteReader())
            {
                while (dbReader.Read())
                {
                    //int iRow = dataTable.Rows.Count; //always zero you never used the datable
                    //MessageBox.Show("Count " + iRow.ToString());
                    //MessageBox.Show(dbReader.ToString());
                    checkedListBox1.Items.Add(dbReader["stckdemge"].ToString());
               //     checkBox1(dbReader[].ToString()

                }

            } //reader closed and disposed
        }//command disposed
    } //connection closed
Posted
Comments
AshishChaudha 1-Mar-13 0:14am    
need more explanation.didn't understand your question..

1 solution

You need to create ListItem object and its Selected property set true value. Please see the code bellow
ASP.NET
<div>
    <asp:checkboxlist runat="server" id="chkList" />
</div>

C#
protected void Page_Load(object sender, EventArgs e)
{
var item = new ListItem("Good Morning");
item.Selected = true;
var item2 = new ListItem("Good AfterNoon");
item2.Selected = true;
var item3 = new ListItem("Good Eventing");
chkList.Items.Add(item);
chkList.Items.Add(item2);
chkList.Items.Add(item3);
}
 
Share this answer
 
v2

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