.net list<T> 轉DataSet
来源:互联网 发布:ros绑定mac 编辑:程序博客网 时间:2024/06/06 17:24
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;namespace AppPhoneInfo{ public partial class Home : System.Web.UI.Page { DBHelp.DBHelpDAL DBhelp = new DBHelp.DBHelpDAL(); protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { List<Model.Model> list = new List<Model.Model>(); list = DBhelp.GetPhoneList(); DataSet ds = list.ToDataSet(); } } public static class ToDataSetMethod//必須為靜態類 { internal static DataSet ToDataSet<T>(this IList<T> list) { Type elementType = typeof(T); var ds = new DataSet(); var t = new DataTable(); ds.Tables.Add(t); elementType.GetProperties().ToList().ForEach(propInfo => t.Columns.Add(propInfo.Name, Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType)); foreach (T item in list) { var row = t.NewRow(); elementType.GetProperties().ToList().ForEach(propInfo => row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value); t.Rows.Add(row); } return ds; } }}
0 0
- .net list<T> 轉DataSet
- c#将List<T>转换成DataSet
- C# 将DataSet转为List<T>
- 【c#】把Dataset类型转为List<T>
- DataSet和List<T> 泛型之间互相转换
- DataSet转换为泛型集合List(Of T)
- DataSet和List<T> 泛型之间互相转换
- DataSet和List<T> 泛型之间互相转换
- 【.Net码农】List<T> 类
- asp.net DataSet转换成List<model>[源码]
- .Net:再现List<T>:相关方法使用
- .NET将字符串转换成List<T>
- .net 讀取DataReader 返回List<T>
- IList(T)转换DataSet
- SQL:DataSet,T-SQL
- MVC4使用微软企业库 dataset foreach遍历 转换成list<T>
- List转换成DataSet
- List转换成DataSet
- sql 查询判断字符串包含中文
- Hibernate 映射关联关系
- GetModuleFileName函数当前运行exe或dll的路径
- java.util.date与java.sql.date转换
- 02面向对象
- .net list<T> 轉DataSet
- 九大全球网络攻击实时追踪系统盘点
- 两种方法教你在Ubuntu下轻松关闭触摸板
- GeoIP的详解 --Python版
- c# winform中treeview判断父节点与子节点的关系
- java中的23种设计模式
- C#:如何去掉groupbox的边框线
- 用toad for oracle将excel数据导入数据库
- http://blog.csdn.net/indexman/article/details/8023740/