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;
           }

  • 相关阅读:
    python selenium
    selenium 遇到chrome 弹出是否保存密码框
    selenium实现在新窗口打开链接
    linux 查看日志
    Selenium+Python :WebDriver设计模式( Page Object )
    Python Logging模块的简单使用
    【工作感悟】——员工因公司而加入,却因中层管理而离开
    【工作感悟】——如何协调人与事?
    J2EE的十三个技术——EJB之消息驱动JMS
    J2EE的十三个技术——EJB之实体Bean
  • 原文地址:https://www.cnblogs.com/cc1120/p/8967768.html
Copyright © 2011-2022 走看看