Click here to Skip to main content
12,828,699 members (54,434 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
My code just like that:

public List<teacher> GetAsssignCoursesOfTeachers(int departmentId)
        {
            SqlConnectionObj.Open();
            string commandString = String.Format("SELECT tbl_TeacherEntry.Name,tbl_Department.Name,tbl_CourseEntry.CourseName From (((tbl_TeacherEntry INNER JOIN tbl_CourseAssignToTeacher ON tbl_TeacherEntry.Id=tbl_CourseAssignToTeacher.TeacherId) INNER JOIN tbl_Department ON tbl_Department.Id=tbl_CourseAssignToTeacher.DepartmentId) INNER JOIN tbl_CourseEntry ON tbl_CourseEntry.Id=tbl_CourseAssignToTeacher.CourseId)");
            commandString += String.Format(" where tbl_CourseAssignToTeacher.DepartmentId=@departmentId");
            SqlCommandObj.CommandText = commandString;
            SqlCommandObj.Parameters.Clear();
            SqlCommandObj.Parameters.Add("@departmentId", SqlDbType.Int);
            SqlCommandObj.Parameters["@departmentId"].Value = departmentId;
            SqlDataReader aDataReader = SqlCommandObj.ExecuteReader();
           List<teacher> teachers=new List<teacher>();
            while (aDataReader.Read())
            {
                Teacher anotherTeacher = new Teacher();
                anotherTeacher.Name = aDataReader["Name"].ToString();
                anotherTeacher.ADepartment.DepartmentName = aDataReader["Name"].ToString();
                anotherTeacher.ACourse.CourseName = aDataReader["CourseName"].ToString();
                teachers.Add(anotherTeacher);
            }
            return teachers;
        }
Posted 27-Dec-12 20:04pm
Updated 27-Dec-12 20:10pm
v3
Comments
Hetal Jariwala 28-Dec-12 1:12am
   
want to show data in grid view? then use data source property of grid view
Zafar Sultan 28-Dec-12 4:01am
   
And the problem?
Sandeep Mewara 28-Dec-12 4:19am
   
And the issue is?
We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
aspnet_regiis -i 31-Dec-12 3:46am
   
Put a quickwatch on the object....
uzzal084052 9-Jan-13 1:49am
   
Thanks for solution.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

public DataSet GetAsssignCoursesOfTeachers(int departmentId)
    {
        DataSet dsTemp = new DataSet();
        SqlDataAdapter daTemp;
        SqlConnectionObj.Open();
        string commandString = String.Format("SELECT tbl_TeacherEntry.Name,tbl_Department.Name,tbl_CourseEntry.CourseName From (((tbl_TeacherEntry INNER JOIN tbl_CourseAssignToTeacher ON tbl_TeacherEntry.Id=tbl_CourseAssignToTeacher.TeacherId) INNER JOIN tbl_Department ON tbl_Department.Id=tbl_CourseAssignToTeacher.DepartmentId) INNER JOIN tbl_CourseEntry ON tbl_CourseEntry.Id=tbl_CourseAssignToTeacher.CourseId)");
        commandString += String.Format(" where tbl_CourseAssignToTeacher.DepartmentId=@departmentId");
        SqlCommandObj.CommandText = commandString;
        SqlCommandObj.Parameters.Clear();
        SqlCommandObj.Parameters.Add("@departmentId", SqlDbType.Int);
        SqlCommandObj.Parameters["@departmentId"].Value = departmentId;
        daTemp = new SqlDataAdapter(SqlCommandObj);
        daTemp.Fill(dsTemp);

        return dsTemp;
        //SqlDataReader aDataReader = SqlCommandObj.ExecuteReader();
        //List<teacher> teachers = new List<teacher>();
        //while (aDataReader.Read())
        //{
        //    Teacher anotherTeacher = new Teacher();
        //    anotherTeacher.Name = aDataReader["Name"].ToString();
        //    anotherTeacher.ADepartment.DepartmentName = aDataReader["Name"].ToString();
        //    anotherTeacher.ACourse.CourseName = aDataReader["CourseName"].ToString();
        //    teachers.Add(anotherTeacher);
        //}
        
    }
</teacher>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100