Hi, I have two datatables and I want to efficiently query the
intersection of the two using the studentID. In my example code below,
I want to print out Mary and Jane and their exam grades and I don't
want to use loop because the real datatables are much larger. Can this
be done using one of the inbuilt methods in the class library and if
so how.
Thank you in advance
Peter
DataTable examgrade;
DataTable students;
private void addExamgrade(int studentID, string grade)
{
DataRow dr=examgrade.NewRow();
dr["STUDENTID"]=studentID;
dr["GRADE"]=grade;
}
private void addstudent(int studentID, string studentname,int
yearenrolled)
{
DataRow dr=students.NewRow();
dr["STUDENTID"]=studentID;
dr["STUDENTNAME"]=studentname;
dr["YEARENROLLED"]=yearenrolled;
}
private void button1_Click(object sender, System.EventArgs e)
{
examgrade=new DataTable();
examgrade.Columns.Add("STUDENTID",typeof(int));
examgrade.Columns.Add("GRADE",typeof(string));
addExamgrade(101,"A");
addExamgrade(102,"B-");
addExamgrade(500,"C");
addExamgrade(150,"FAIL");
students=new DataTable();
students.Columns.Add("STUDENTID",typeof(int));
students.Columns.Add("STUDENTNAME",typeof(string)) ;
students.Columns.Add("YEARENROLLED",typeof(int));
addstudent(400,"Fred",1982);
addstudent(300,"John",1975);
addstudent(100,"Mark",2003);
addstudent(500,"Mary",1960);
addstudent(150,"Jane",2002);
//hardcoded answer
Console.WriteLine("The students and their grades are");
Console.WriteLine("Mary C");
Console.WriteLine("Jane FAIL");
}