0
Hi try this
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);
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;
}
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();
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;
}
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();
}
}
}
