Click here to Skip to main content
Rate this: bad
good
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 19:04pm
Edited 27-Dec-12 19:10pm
v3
Comments
Hetal Jariwala at 28-Dec-12 1:12am
   
want to show data in grid view? then use data source property of grid view
Zafar Sultan at 28-Dec-12 4:01am
   
And the problem?
Sandeep Mewara at 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 at 31-Dec-12 3:46am
   
Put a quickwatch on the object....
uzzal084052 at 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></teacher>
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 424
1 Nirav Prabtani 298
2 OriginalGriff 199
3 _Amy 165
4 Maciej Los 145
0 OriginalGriff 7,755
1 Sergey Alexandrovich Kryukov 6,951
2 Maciej Los 3,994
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
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