Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code for databinding of cheakellistbox
C#
//***********************************************************************************
public void FillCheckedListBox1party()
        {
            try
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }

                string commandString = "SELECT NAME ,AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'";
               
                DataTable accTable = new DataTable();
                SqlCommand cmd = new SqlCommand(commandString, con);
                SqlDataAdapter adpObj = new SqlDataAdapter(cmd);
                accTable.TableName = "tbl";
                adpObj.Fill(accTable);
                con.Close();
                checkedListBox1.DataSource = accTable;
                checkedListBox1.ValueMember = "AC_CODE";
                checkedListBox1.DisplayMember ="NAME";
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                con.Close();
            }


here for stringbulder
C#
if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }
           StringBuilder query = new StringBuilder("SELECT ITEMCODE, BROKTYPE,BROKRATE,TRANRATE,TranType,uptostdt,MARTYPE,MARRATE FROM PITBROK ");
           query.AppendFormat("where    ");
           for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
           {
               int coun = checkedListBox1.CheckedItems.Count;
               coun = coun - 1;

query.AppendFormat("PITBROK.AC_CODE='{0}' ", checkedListBox1.CheckedItems[value]);

               if (i < coun)
               {
                   query.AppendFormat("  and    ");
               }

at strike(query.AppendFormat("PITBROK.AC_CODE='{0}' ",checkedListBox1.CheckedItems[value];)
i want to pass AC_CODE OF all CHeackeditem....
can any buddy Help me .............
Posted
Updated 30-Dec-11 2:51am
v2

Try using IN

where AC_CODE in(...add check box values...)
 
Share this answer
 
if(checkedListBox1 .CheckedItems.Count>0)
{
DataRow row;
row = ((DataRowView) this.checkedListBox1.CheckedItems[i]).Row;
val= (row[this.checkedListBox1.ValueMember]).ToString();
row = null;

query.AppendFormat("PITBROK.AC_CODE='{0}' ", val.ToString());
 
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