I took attandance field in my table tbl_Attandance,so i need to satisfy the condition of the attandance out of 100.Its not satisfying..Wats the problem in this code .Can anyone help me
This is my Code.
private void SaveData()
{
int attendance = 100;
if (txtsn.Text == "")
{
MessageBox.Show("Select The Student Name");
txtsn.Focus();
}
else
if (cbosem.Text == "---Select Semister---")
{
MessageBox.Show("Select The Semister");
cbosem.Focus();
}
else
if (txtdep.Text == "")
{
MessageBox.Show("Select The Department");
txtdep.Focus();
}
else
if (cbosub.Text == "---Select Subject---")
{
MessageBox.Show("Select The Subject");
cbosub.Focus();
}
else
if (txtattnd.Text == "")
{
MessageBox.Show("Enter The Attandance");
txtattnd.Focus();
}
else
if (attendance >= 80)
{
MessageBox.Show("Eligible for The Exam ");
}
else if (attendance >= 75)
{
MessageBox.Show("Not Eligible for The Exam ");
}
else if (attendance == 40){
MessageBox.Show("Shortage Of Attandance");
}
else
{
MessageBox.Show("Do You Like To Insert Into Attandance Record?", "Save", MessageBoxButtons.YesNo);
SqlConnection con = new SqlConnection(connectionString);
try
{
string Query = "insert into tbl_attendance(studentid,semid,subjectid,attend)values('" + label15.Text + "','" + label6.Text + "','" + label5.Text + "','"+txtattnd .Text +"') ";
SqlCommand cmd = new SqlCommand(Query, con);
cmd.CommandText = Query;
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("Successfully Inserted...");
return;
}
}
catch
{
MessageBox.Show("Error in Connection");
}
Display();
clear(); //close the connection
con.Close();
GroupBox1.Enabled = false;
}
}


VulpesRank #55 · 29.2K reputationPosted Feb 15, 2014, 2:15 PM EST
So are you saying that this one isn't executing and, if so, what is the MessageBox showing ?
Sathya Narayan148 reputationPosted Feb 19, 2014, 8:17 PM EST
VulpesRank #55 · 29.2K reputationPosted Feb 20, 2014, 1:39 PM EST
What's the second message here?
Can you highlight the part of the code that's getting executed.
Sathya Narayan148 reputationPosted Feb 20, 2014, 8:34 PM EST
else if (attendance >= 75)
VulpesRank #55 · 29.2K reputationPosted Feb 21, 2014, 12:59 AM EST
The flow of execution moves down the if/else ladder until it finds a block where the condition is true. It then executes the appropriate code and jumps to the end of the ladder, continuing execution from there.
So, if attendance is set to 100, the first block for which the condition is true is this one:
So this one gets executed and the remaining blocks in the ladder are skipped.
If you'd have set attendance to 79, this block would have been executed instead: