zoukankan      html  css  js  c++  java
  • DataRow转化成对象

     #region 把DataRow转化成对象
            /// <summary>
            /// 把DataRow转化成对象
            /// </summary>
            /// <param name="dr">dr</param>
            /// <param name="obj">对象</param>
            /// <returns></returns>
            public static object DataRowToObj(System.Data.DataRow dr, object obj)
            {
                try
                {
                    if (dr != null && obj != null)
                    {
                        Type t = obj.GetType();
                        PropertyInfo[] f = t.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
                        string tableName = t.Name;
                        foreach (PropertyInfo pi in f)
                        {
                            string field = pi.Name;
                            if (dr.Table.Columns.Contains(field) && dr[field] != DBNull.Value)
                                pi.SetValue(obj, dr[field], null);
                        }
                    }
                }
                catch (Exception ex)
                {
                    new Exception(ex.ToString());
                    return null;
                }
                return obj;
            }
            #endregion
  • 相关阅读:
    java 寒假作业
    java 搭积木
    java 移动距离
    java 垒骰子
    java 饮料换购
    java 牌型种数
    ONOS基础教程(QuickStart with a VM)
    Java中 VO、 PO、DO、DTO、 BO、 QO、DAO、POJO的概念
    PM2使用基本介绍
    nodejs项目部署
  • 原文地址:https://www.cnblogs.com/bloodyboy/p/3023732.html
Copyright © 2011-2022 走看看