0

hi
I have a problem of counting number listed in my listbox
my list box databinded by sql
I wanna to add the whole numbers on my

public string connString = "server=(local)\\SQLEXPRESS;database=PWA_RES;Integrated Security=SSPI";
        public int pul;
        private void Form1_Load(object sender, EventArgs e)
        {            
            string sql = @"select name,price from main_course ";

            SqlConnection conn = new SqlConnection(connString);
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            da.Fill(dataSet1, "main_course");
            DataTable dt = dataSet1.Tables["main_course"];

            listBox1.DataSource = dt;
            listBox1.DisplayMember = "name";

            label1.DataBindings.Add("text", dt, "name");
        }

         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Add(label1.Text);                  
        }
          private void button3_Click(object sender, EventArgs e)
        {
            pul = 0;
            for (int i = 0; i <= listBox5.Items.Count;i++ )
         {
                pul =pul +  Convert.ToInt32(listBox5.Items[i].ToString()) ;

           }
           MessageBox.Show(pul.ToString());

        }

list box
thanks

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by tinstaafl
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.