博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
类型转换
阅读量:7070 次
发布时间:2019-06-28

本文共 1598 字,大约阅读时间需要 5 分钟。

#region List <=> DataTable 互相转换        ///          /// LINQ返回DataTable类型        ///          /// 
/// ///
public static DataTable ListToDataTable
(IEnumerable
varlist) { DataTable dtReturn = new DataTable(); // column names PropertyInfo[] oProps = null; if (varlist == null) return dtReturn; foreach (T rec in varlist) { if (oProps == null) { oProps = ((Type)rec.GetType()).GetProperties(); foreach (PropertyInfo pi in oProps) { Type colType = pi.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))) { colType = colType.GetGenericArguments()[0]; } dtReturn.Columns.Add(new DataColumn(pi.Name, colType)); } } DataRow dr = dtReturn.NewRow(); foreach (PropertyInfo pi in oProps) { dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue (rec, null); } dtReturn.Rows.Add(dr); } return dtReturn; }

 

posted on
2016-03-03 17:13 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/volts0302/p/5239345.html

你可能感兴趣的文章
python曲线拟合
查看>>
Linux & Vim Command Wallpaper
查看>>
Linux常用命令备忘
查看>>
小程序右上角转发分享web-view页面(备份前端网)
查看>>
virtualbox linux虚拟机相关
查看>>
关于.net和java我的见解
查看>>
【Android】设置Dialog点击屏幕不消失
查看>>
ConcurrentDictionary与Dictionary
查看>>
Atom Remote-FTP connecting FTP with SSL/TLS
查看>>
《代码大全》阅读笔记-27-程序规模对构建的影响
查看>>
What is R语言
查看>>
【给你一个承诺 - 玩转 AngularJS 的 Promise】
查看>>
P4962 朋也与光玉
查看>>
关于flash cs4意外退出的问题
查看>>
一道笔试指针题目详解
查看>>
easyui datagrid 绑定从后台得到的复杂的特殊数据结构
查看>>
makefile 字符串处理函数
查看>>
Class Prefix(Xcode6以后设置类前缀)
查看>>
(转载)创业型公司如何管理-吸引人才
查看>>
Oracle Spool教程
查看>>