We need to convert the Datatable dt to Array of objects StudentListResponse
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(dt);
var list = dt.AsEnumerable()
.Skip(1)
.Select(dr =>
new StudentListResponse
{
id = dr["PKStudentID"].ToString(),
name = dr["StudentName"].ToString(),
profile_pic = dr["PhotoURL"].ToString()
}
).ToList();
StudentListResponse[] students = list.ToArray();
Its very simple as explained in the previous post to convert Datatable to Object list. Just convert the list to Array as highlighted above.
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(dt);
var list = dt.AsEnumerable()
.Skip(1)
.Select(dr =>
new StudentListResponse
{
id = dr["PKStudentID"].ToString(),
name = dr["StudentName"].ToString(),
profile_pic = dr["PhotoURL"].ToString()
}
).ToList();
StudentListResponse[] students = list.ToArray();
Its very simple as explained in the previous post to convert Datatable to Object list. Just convert the list to Array as highlighted above.


