here i post the code that i wrote
i take the stage and depId from two textboxs and beging to excute the queries usin tabel adapter and put the desired result in arrayList then because the tableadpter StudentCourses1 can't up date the dataset as contain multiple table so i use table studentCourses
ex:
getStudentCoursesby DepID and StageID
-----------------------------------------------------------------------------------------------
SELECT student_courses.StudentID,
student_courses.stage_id, student_courses.the_year,
student_courses.course_id, student_courses.term_id,
student_courses.dept_id, student_courses.main_dept_id,
student_courses.minor_dept_id, student_courses.mid_term_grade,
student_courses.year_work, student_courses.oral,
student_courses.final_exam_grade, student_courses.intial_total,
student_courses.final_total,
student_courses.control_action_id,
student_courses.raise_marks
FROM student_courses INNER JOIN
courses ON student_courses.course_id = courses.ID
INNER JOIN
staff_courses ON courses.ID = staff_courses.CourseID
WHERE (student_courses.stage_id = @stage_id) AND
(student_courses.dept_id = @dept_id)
ORDER BY student_courses.StudentID, .5 * staff_courses.Total -
student_courses.intial_total
--------------------------------------------------------------------------------------------------
then i try to update with the studentCourses but he only update the first field
code in c#:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;using AkhbarTableAdapters;
public
partial class Control_Action : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//-------protected void Button1_Click(object sender, EventArgs e)
{
int StageID = int.Parse(StageIdTextBox.Text);
int DepID = int.Parse(DepIdTextBox.Text);
// double celmencyScore = CalculateClemencyPercentage(StageID,DepID); double clemencyScore = 10;
ArrayList faildStudentList = new ArrayList();staff_coursesTableAdapter adapter = new staff_coursesTableAdapter();
Akhbar.staff_coursesDataTable StaffCourses = adapter.GetCourseTotalByDepIDStageID(StageID,DepID);
//student_courses1TableAdapter StudentCoursesAdapter = new student_courses1TableAdapter();
Akhbar.student_courses1DataTable StudentCourses = StudentCoursesAdapter.GetStudentCoursesByDepIdANDStageID(StageID, DepID);
//
//loopforeach(Akhbar.student_courses1Row studentCourse in StudentCourses)
{
double ScorePerStudent = clemencyScore;foreach (Akhbar.staff_coursesRow StaffCourse in StaffCourses)
{
if (ScorePerStudent != 0 && studentCourse.course_id == StaffCourse.CourseID &&
studentCourse.intial_total < (StaffCourse.Total * .5) &&
studentCourse.intial_total > (StaffCourse.Total * .4))
{
int temp = (StaffCourse.Total) / 2;
int Diff = temp - studentCourse.intial_total;if (Diff <= ScorePerStudent)
{
faildStudentList.Add(studentCourse.StudentID);
faildStudentList.Add(studentCourse.course_id);
int finalTotal = studentCourse.intial_total + Diff;
faildStudentList.Add(finalTotal);
ScorePerStudent = ScorePerStudent - Diff;
}
}
}
ScorePerStudent = clemencyScore;
//re intaillize the clemency for the next student
}
for (int i = 0; i < faildStudentList.Count; i++)
{
Response.Write(faildStudentList[i] + " --");
}
student_coursesTableAdapter IslamAdapter = new student_coursesTableAdapter();
Akhbar.student_coursesDataTable student_courses = IslamAdapter.GetData();int size= faildStudentList.Count;
int x =0;foreach(Akhbar.student_coursesRow student_Course in student_courses)
{
if (x < size && Convert.ToInt32(faildStudentList[x]) == student_Course.StudentID && Convert.ToInt32(faildStudentList[x + 1]) == student_Course.course_id)student_Course.final_total = int.Parse(faildStudentList[x + 2].ToString());
x = x + 3;
}
IslamAdapter.Update(student_courses);
}
public double CalculateClemencyPercentage(int s,int d) // here we sum the courses from a specefic departemtn and groups and calculater the percentage to get how many score we can add for one student
{
int Total = 0;
staff_coursesTableAdapter adapter = new staff_coursesTableAdapter();Akhbar.staff_coursesDataTable StaffCourses = adapter.GetCourseTotalByDepIDStageID(s, d);foreach (Akhbar.staff_coursesRow StaffCourse in StaffCourses)
{
Total = Total + StaffCourse.Total;
}
result.Text = Total.ToString();
return Total;
}
}