Afzal Mozan

Afzal Mozan

  • NA
  • 17
  • 9.9k

Display total no of record(rollno) from mysql database

Oct 28 2014 12:34 PM
Hello dear programer(s),
        i am creating attendance application,i am selecting the total count of roll-number field from mysql database table attendance.
i am using three combobox one is stream,second is course and third is division.
after the combobox item is selected (three of three) then diaplay total count in label text it is work fine but one problem is that i change the any combobox value is changed at run time the total count is not changed, so how can i do after the change of any combo item. please help me.
note: i put the database logic in in third combobox selected index changed event.
code:
namespace Attendance_Application
{
    public partial class bwaapp : Form
    {
        string constring = "SERVER='localhost';DATABASE='bwiitm';UID='root';PASSWORD='';";
        MySqlConnection con;
        DataSet ds = new DataSet();
        string coursecombo;
        string semcombo;
        string divcombo;
        public bwaapp()
        {
            InitializeComponent();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex > -1)
            {  
                coursecombo = comboBox1.SelectedItem.ToString();
                con = new MySqlConnection(constring);

            }
            else
            { }
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex > -1)
            {
                semcombo = comboBox2.SelectedItem.ToString();
            }
        }
        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox3.SelectedIndex > -1)
            {
                divcombo = comboBox3.SelectedItem.ToString();
            }
            try
            {
                con = new MySqlConnection(constring);
                MySqlDataAdapter daroll = new MySqlDataAdapter("SELECT count(rollno)FROM attendance where course='" + coursecombo + "'and sem='" + semcombo + "'and division='" + divcombo + "'", con);
                daroll.Fill(ds, "roll_no");
                label9.Text=ds.Tables["roll_no"].Rows[0][0].ToString()+" Students";
                label9.ForeColor = Color.Red;
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Dispose();
                }
            }
        }



Answers (1)