public static StudentModel ToObject(DataRow reader) { StudentModel studentModel = new StudentModel(); studentModel.personId = reader[0].ToString(); try { studentModel.personFirstName = reader[1].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personFirstName:" + ex.Message); } try { studentModel.personLastName = reader[2].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personLastName:" + ex.Message); } try { studentModel.personBeforeTelephone = reader[3].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personBeforeTelephone:" + ex.Message); } try { studentModel.personTelephone = reader[4].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personTelephone:" + ex.Message); } try { studentModel.personBeforeCellphone = reader[5].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personBeforeCellphone:" + ex.Message); } try { studentModel.personCellphone = reader[6].ToString(); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personCellphone:" + ex.Message); } try { studentModel.personCode = int.Parse(reader[7].ToString()); } catch (IndexOutOfRangeException ex) { Debug.WriteLine("personCode:" + ex.Message); } studentModel.studentId = reader[8].ToString(); studentModel.studentFacultyCode = reader[9].ToString(); studentModel.studentYear = int.Parse(reader[10].ToString()); studentModel.studentType = int.Parse(reader[11].ToString()); Debug.WriteLine("StudentModel:" + studentModel.ToString()); return(studentModel); }