List<T> 和DataTable的相互转换】的更多相关文章

1.这里下载:http://www.newtonsoft.com/products/json/ 安装:    解压下载文件,得到Newtonsoft.Json.dll    在项目中添加引用 2.引入命名空间 创建一个DataTable对象: DataTable dt = new DataTable(); DataColumn dcName = new DataColumn("Name"); DataColumn dcAge = new DataColumn("Age&quo…
我用的将集合类转换为DataTable 的方法 /// <summary> /// 将集合类转换成DataTable /// </summary> /// <param name="list">集合</param> /// <returns></returns> private static DataTable ToDataTableTow(IList list) { DataTable result = new…
public static DataTable ToDataTableTow(IList list) { DataTable result = new DataTable(); ) { PropertyInfo[] propertys = list[].GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { result.Columns.Add(pi.Name, pi.PropertyType); } ; i < l…
1.List转DataTable /// <summary> /// list to datatable /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collection"></param> /// <returns></returns> public DataTable Lis…
1 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Collections; using System.Web.Script.Serialization; /// <summary> ///JsonHelper 的摘要说明 /// </summary> public class JsonHelper…
using Excel = Microsoft.Office.Interop.Excel; private static Excel.Application m_xlApp = null; /// <summary>   /// 将DataTable数据导出到Excel表   /// </summary>   /// <param name="tmpDataTable">要导出的DataTable</param>public static…
1.DataTable转换成XML public string ConvertDataTableToXML(DataTable xmlDS) { MemoryStream stream = null; XmlTextWriter writer = null; try { stream = new MemoryStream(); writer = new XmlTextWriter(stream, Encoding.UTF8); xmlDS.WriteXml(writer); int count…
List转DataTable: public static DataTable ToDataTable<T>(IEnumerable<T> collection) { var props = typeof(T).GetProperties(); var dt = new DataTable(); dt.Columns.AddRange(props.Select(p => new DataColumn(p.Name, p.PropertyType)).ToArray()); )…
1 #region DataTable 转换为Json字符串实例方法 2 /// <summary> 3 /// GetClassTypeJosn 的摘要说明 4 /// </summary> 5 public class GetClassTypeJosn : IHttpHandler 6 { 7 /// <summary> 8 /// 文件名:DataTable 和Json 字符串互转 9 /// 版权所有:Copyright (C) Create Family We…
之前做DataTable和DataSet转xml一直使用XmlSerializer 序列化完成.今天发现新方法,哇咔咔方便了很多.还不用担心Name为空时报错 static void Main(string[] args) { DataTable dt = new DataTable(); dt.TableName = "dtABC"; dt.Columns.Add("CloumnA"); dt.Columns.Add("CloumnB"); d…