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;
}
}

VulpesPosted Feb 21, 2014, 5:59 AM
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:
Sathya NarayanPosted Feb 21, 2014, 1:34 AM
else if (attendance >= 75)
VulpesPosted Feb 20, 2014, 6:39 PM
What's the second message here?
Can you highlight the part of the code that's getting executed.
Sathya NarayanPosted Feb 20, 2014, 1:17 AM
VulpesPosted Feb 15, 2014, 7:15 PM
So are you saying that this one isn't executing and, if so, what is the MessageBox showing ?