Carlos kambui

Carlos kambui

  • NA
  • 499
  • 125.6k

c# class what could be the problem with this?

May 7 2015 5:00 AM
 public List<StudentType> GetStudentTypes()
{
            StudentType  tStudent = new StudentType();
            List<StudentType> student = new List<StudentType>();
BuildConnstring ();
using (SqlConnection conn = new SqlConnection (connstring))
{
using (SqlCommand Command = conn.CreateCommand ())
{
conn.Open ();
Command.CommandText = "select * from student";
                    Command.CommandType = CommandType.Text;
                    dbAdapter.SelectCommand = Command;
ds.Clear ();
ds.DataSetName = "User";
dbAdapter.Fill (ds);
}
}
                    if (tStudent.adm_no > 0)
{
                        if (ds.Tables[0].Rows.Count == 1)
{                 
 for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) 

{
tStudent = new StudentType();
//tStudent.student_id = Convert.ToInt32 (ds.Tables [0].Rows [i] ["student_id"]);
tStudent.adm_no = Convert.ToInt32 (ds.Tables [0].Rows [i] ["adm_no"]);
tStudent.first_name = ds.Tables [0].Rows [i] ["first_name"].ToString ();
tStudent.last_name = ds.Tables [0].Rows [i] ["last_name"].ToString ();
tStudent.sir_name = ds.Tables [0].Rows [i] ["sir_name"].ToString ();
tStudent.id_no = ds.Tables [0].Rows [i] ["id_no"].ToString ();
tStudent.dob = ds.Tables [0].Rows [i] ["dob"].ToString ();
tStudent.Sex = ds.Tables [0].Rows [i] ["Sex"].ToString ();
 student.Add(tStudent);
}

                        }
                    }
                    return student;
        }

Answers (3)