protected void BTNADDED_Click1(object sender, EventArgs e) { int num = 0; string sql = "select * from [DepartmentCourses] where Department='" + Session["Department"] + "' and Year='" + Session["Year"] + "' and Semster='" + Session["Semester"] + "'"; DataTable dt = DBFunctions.SelectFromTable(sql); GridViewRegistering.DataSource = (dt); // DataTable dt1=null; if (((CheckBox)GridViewRegistering.Rows[0].FindControl("CheckBox1")).Checked == true) { string s = dt.Rows[0]["IdCourse"].ToString(); string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; DataTable dt2 = DBFunctions.SelectFromTable(sql2); string muchStudents = dt.Rows[0]["RegisteredStudents"].ToString(); string maxStudent = dt.Rows[0]["MaxStudent"].ToString(); StudentAtCourse c = new StudentAtCourse(s, Session["ID"].ToString()); if (Convert.ToInt32(muchStudents) < Convert.ToInt32(maxStudent)) { if (c.insertCourseForStudent()) { num = Convert.ToInt32(muchStudents) + 1; DepartmentCourses d = new DepartmentCourses(num.ToString(), maxStudent, s); d.UpdateRegisteringStudent(); lblMsn.Visible = true; lblMsn.Text = "Has Been Added"; } else { lblMsn.Visible = true; lblMsn.Text = "Already Exsist!"; } dt1 = DBFunctions.SelectFromTable(sql2); } } for (int i = 1; i < dt.Rows.Count; i++) { if (((CheckBox)GridViewRegistering.Rows[i].FindControl("CheckBox1")).Checked == true) { string s = dt.Rows[i]["IdCourse"].ToString(); string muchStudents = dt.Rows[i]["RegisteredStudents"].ToString(); string maxStudent = dt.Rows[i]["MaxStudent"].ToString(); StudentAtCourse c = new StudentAtCourse(s, Session["ID"].ToString()); if (Convert.ToInt32(muchStudents) < Convert.ToInt32(maxStudent)) { if (c.insertCourseForStudent()) { num = Convert.ToInt32(muchStudents) + 1; DepartmentCourses d = new DepartmentCourses(num.ToString(), maxStudent, s); d.UpdateRegisteringStudent(); lblMsn.Visible = true; lblMsn.Text = "Has Been Added"; } else { lblMsn.Visible = true; lblMsn.Text = "Already Exsist!"; } } else { lblMsn.Visible = true; lblMsn.Text = "There is no place in this course!"; } string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; DataTable dt2 = DBFunctions.SelectFromTable(sql2); if (dt1 == null) { dt1 = dt2; } else { dt1.Merge(dt2); } } } GridViewAdded.DataSource = (dt1); newDt = DBFunctions.CopyDataTable(dt1, dt1.Rows.Count); DataBind(); }