We Help You To Renovate Your Blogger Blog With Awesomeness!

Showing posts with label ASP MVC. Show all posts
Showing posts with label ASP MVC. Show all posts

Friday, April 15, 2016

  • Conevert Datatable to Object Array C# ASP.Net / ASP MVC

    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.



  • Conevert Datatable to Object List C# ASP.Net / ASP MVC



      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();



    Here dt is the DataTable Holds data.
    And StudentListResponse object list is created.


  • Copyright @ 2013 Code Snippets.