zoukankan      html  css  js  c++  java
  • C#将DataTable转换为List<>泛型集合

      /// <summary>
           /// 得到一个转载多个实体对象的泛型集合
           /// </summary>
           /// <returns>泛型集合</returns>
           public List<MODEL.ModelXtUserGroup> GetXtUserGroupModel()
           {
               List<MODEL.ModelXtUserGroup> list = null;
               StringBuilder sb = new StringBuilder("select SysId,GroupId,GroupName,CreateDate,CreateUser,LastModifyDate,LastModifyUser,DelFlag FROM XtUserGroup ");
               sb.Append("where SysId = 'MedicalApp' and DelFlag ='0'");
               DataTable dt = DBUtility.DbHelperSQL.QueryTable(sb.ToString());
               if (dt.Rows.Count > 0)
               {
                   list = new List<MODEL.ModelXtUserGroup>();
                   foreach (DataRow dr in dt.Rows)
                   {
                       list.Add(DataRowToModel(dr));
                   }
               }
               return list;
           }

      public MODEL.ModelXtUserGroup DataRowToModel(DataRow row)
           {
               MODEL.ModelXtUserGroup model = new MODEL.ModelXtUserGroup();
               if (row != null)
               {
                   if (row["SysId"] != null)
                   {
                       model.SysId = row["SysId"].ToString();
                   }
                   if (row["GroupId"] != null)
                   {
                       model.GroupId = row["GroupId"].ToString();
                   }
                   if (row["GroupName"] != null)
                   {
                       model.GroupName = row["GroupName"].ToString();
                   }
                   if (row["CreateDate"] != null && row["CreateDate"].ToString() != "")
                   {
                       model.CreateDate = DateTime.Parse(row["CreateDate"].ToString());
                   }
                   if (row["CreateUser"] != null)
                   {
                       model.CreateUser = row["CreateUser"].ToString();
                   }
                   if (row["LastModifyDate"] != null && row["LastModifyDate"].ToString() != "")
                   {
                       model.LastModifyDate = DateTime.Parse(row["LastModifyDate"].ToString());
                   }
                   if (row["LastModifyUser"] != null)
                   {
                       model.LastModifyUser = row["LastModifyUser"].ToString();
                   }
                   if (row["DelFlag"] != null)
                   {
                       model.DelFlag = row["DelFlag"].ToString();
                   }
               }
               return model;
           }

  • 相关阅读:
    在EasyDarwin进行实时视频转发的两种模式
    Windows服务中读取配置文件的方法
    reactor设计模式
    用Darwin实现流媒体转发程序(附源码)
    Windows服务中读取配置文件的方法
    c# 参数 this
    基于DSS的先侦听后推送式流媒体转发
    用live555做本地视频采集转发,附源码
    Darwin在转发流过程中对推送端断开的处理问题
    基于live555的流媒体代理转发服务器
  • 原文地址:https://www.cnblogs.com/cc1120/p/8967768.html
Copyright © 2011-2022 走看看