Store data from DataTable to List Generic Class in c#

List is a strongly typed list of objects that can be accessed by index. 
It can be found under System.Collections.Generic namespace.

    DataTable dt = ds.Tables[0];
    List<clsDispatch> DispatchDetails = new List<clsDispatch>();

                List<clsDispatch> DispatchDetails = new List<clsDispatch>();
                        DispatchDetails = (from DataRow row in dt.Rows
                               select new clsDispatch
                               {
                                   DespID = Convert.ToInt64(row["DespID"].ToString()),
                                   DispatchDate = row["DispatchDate"].ToString(),
                                   DispatchType = row["DispatchType"].ToString(),
                                   DispRemark = row["DispRemark"].ToString(),
                                   Createdby = Convert.ToInt64(row["Createdby"].ToString()),
                                   CreationOn = row["CreationOn"].ToString(),
                                   Updationby = row["Updationby"].ToString(),
                                   UpdationOn = row["UpdationOn"].ToString(),
                                   IsActive = (row["IsActive"].ToString() == "1") ? true : false
                               }).ToList();



Create Class Disptch;

 public class clsDispatch
    {
        public clsDispatch()
        {

        }


        public Int64 m_DespID;

        public Int64 DespID { get { return m_DespID; } set { m_DespID = value; } }

        private string m_DispatchDate;
        public string DispatchDate { get { return m_DispatchDate; } set { m_DispatchDate = value; } }

        private string m_DispatchType;
        public string DispatchType { get { return m_DispatchType; } set { m_DispatchType = value; } }


        private string m_DispRemark;
        public string DispRemark { get { return m_DispRemark; } set { m_DispRemark = value; } }


        private Int64 m_Createdby;

        public Int64 Createdby { get { return m_Createdby; } set { m_Createdby = value; } }

        private string m_CreationOn;
        public string CreationOn { get { return m_CreationOn; } set { m_CreationOn = value; } }

        public string m_Updationby;
        public string Updationby { get { return m_Updationby; } set { m_Updationby = value; } }

        public string m_UpdationOn;
        public string UpdationOn { get { return m_UpdationOn; } set { m_UpdationOn = value; } }

        private bool m_IsActive;
        public bool IsActive { get { return m_IsActive; } set { m_IsActive = value; } }


    }



Comments

  1. Great job Mr. Mehul Meheriya....
    nice article you have posted here..
    you have some examples about gried view and repeater then please send me on my mail id,
    and my mail id is vivekchandra09@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Validate Mobile Number with 10 Digits in ASP.Net