C# 中List<T>与DataSet之间的转换
p{
text-align:center;
}
blockquote > p > span{
text-align:center;
font-size: 18px; color: #ff0000;
}
-->
C# 中List<T>与DataSet之间的转换
public static DataSet ConvertToDataSet<T>(List<T> list)
{
if (list == null || list.Count <= )
{
return null;
} DataSet ds = new DataSet();
DataTable dt = new DataTable(typeof(T).Name);
DataColumn column;
DataRow row; System.Reflection.PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (T t in list)
{
if (t == null)
{
continue;
} row = dt.NewRow(); for (int i = , j = myPropertyInfo.Length; i < j; i++)
{
System.Reflection.PropertyInfo pi = myPropertyInfo[i]; string name = pi.Name; if (dt.Columns[name] == null)
{
column = new DataColumn(name, pi.PropertyType);
dt.Columns.Add(column);
} row[name] = pi.GetValue(t, null);
} dt.Rows.Add(row);
}
ds.Tables.Add(dt);
return ds;
}
C# 中List<T>与DataSet之间的转换的更多相关文章
- MFC中char*,string和CString之间的转换
MFC中char*,string和CString之间的转换 一. 将CString类转换成char*(LPSTR)类型 方法一,使用强制转换.例如: CString theString( &q ...
- 【转】Android中dip(dp)与px之间单位转换
Android中dip(dp)与px之间单位转换 dp这个单位可能对web开发的人比较陌生,因为一般都是使用px(像素)但是,现在在开始android应用和游戏后,基本上都转换成用dp作用为单位了,因 ...
- shell 脚本文件十六进制转化为ascii码代码, Shell中ASCII值和字符之间的转换
Shell中ASCII值和字符之间的转换 1.ASCII值转换为字符 方法一: i=97 echo $i | awk '{printf("%c", $1)}' ...
- Java中String与Date格式之间的转换
转自:https://blog.csdn.net/angus_17/article/details/7656631 经常遇到string和date之间的转换,把相关的内容总结在这里吧: 1.strin ...
- Java中二进制数与整型之间的转换
import java.io.*; public class Test{ /** * 二进制与整型之间的转换 * @param args * @throws IOException */ public ...
- java中unicode utf-8以及汉字之间的转换工具类
1. 汉字字符串与unicode之间的转换 1.1 stringToUnicode /** * 获取字符串的unicode编码 * 汉字"木"的Uni ...
- js中数值各进制之间的转换
十进制转换为二进制 toString()方法可把一个 Number 对象转换为一个字符串,并返回结果.语法如下: NumberObject.toString(radix); 其中,radix为可选.规 ...
- python中字母与ASCII码之间的转换以及进制间的转换
字母与ascii码: ord(c):参数是长度为1的字符串,简称字符.当参数为统一对象时(unicode object),返回能代表该字符的统一编码,当参数为8比特的字符串时,返回该字节的值.例如,o ...
- C++中GB2312字符串和UTF-8之间的转换
在编程过程中需要对字符串进行不同的转换,特别是Gb2312和Utf-8直接的转换.在几个开源的魔兽私服中,很多都是老外开发的,而暴雪为了能 够兼容世界上的各个字符集也使用了UTF-8.在中国使用VS( ...
随机推荐
- NOIP-Cantor表
题目描述 现代数学的著名证明之一是Georg Cantor证明了有理数是可枚举的.他是用下面这一张表来证明这一命题的: 我们以Z字形给上表的每一项编号.第一项是1/1,然后是1/2,2/1,3/1,2 ...
- css3 属性
1.css 面试题: css 组成: css 样式组成 规则:选择器+声明块 声明块:css属性+css属性值 2.css 解析规则: 从右往左 3.文字超出省略号显示: 1.元素不是内联块 2.ov ...
- less 基础+ flex
1.less 中的变量 @ 符号 引入 /*普通变量*/ @color:pinker; .styles{ color:@color; } /*选择器变量*/ @I:img; @{I}{ width: ...
- Python通过简单的文件读写,来实现注册登录
# -*- coding:utf-8 -*- '''''' username = input('请输入您的姓名:') password = input('请输入密码:') with open('get ...
- JavaScript关于md5加密
/*中文加密 *181009 * */ function md5(string) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S ...
- WinAPI 字符及字符串函数(5): IsCharAlpha - 是否是个字母
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- jeecg自定义按钮使用exp属性不起作用
为什么要写这篇文章? 之前写过一篇类似的文章 jeecg笔记之自定义显示按钮exp属性,但是有些小伙伴留言参考后不起作用,当时我的 jeecg 版本为3.7.5,最终以版本不同,暂时搁浅了.今天,重新 ...
- Oracle中exp导出与imp导入的参数(full,owner/formuser/touser)测试
1.exp导出的参数(FULL,OWNER)测试 先知道的一点是full不能与owner共存,还有都是以用户的方式导出(在这里),其中不仅仅包括表,这可能就是下面报warnings的原因,因为Orac ...
- Jenkins + Gerrit + Git
参考:https://blog.csdn.net/mr_raptor/article/details/76223233 https://www.cnblogs.com/kevingrace/p/565 ...
- 谷歌AM HTML视频代码amp-video示例
ntroduction Use amp-video to embed videos into your AMP HTML files. Video source files must be serve ...