DataTable与List<T>互转 1.List<T>转DataTable public static DataTable ListToDataTable<T>(List<T> list) { ) { return new DataTable(); } //获取T下所有的属性 Type entityType = list[].GetType(); PropertyInfo[] entityProperties = entityType.GetProper…
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…
之前做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…
/// <summary>/// 将json转换为DataTable/// </summary>/// <param name="strJson">得到的json</param>/// <returns></returns>private DataTable JsonToDataTable(string strJson){    //转换json格式    strJson = strJson.Replace(&qu…
DataView view = new DataView();view.Table = DataTableA;view.RowFilter = "itemType = 'book'";//itemType是DataTableA中的一个字段DataTableB= view.ToTable();或者:DataRow[] rows = DataTableA.Select("itemType = 'book'");DataTableB= DataTableA.Clone()…
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…
using Excel = Microsoft.Office.Interop.Excel; private static Excel.Application m_xlApp = null; /// <summary>   /// 将DataTable数据导出到Excel表   /// </summary>   /// <param name="tmpDataTable">要导出的DataTable</param>public static…
我用的将集合类转换为DataTable 的方法 /// <summary> /// 将集合类转换成DataTable /// </summary> /// <param name="list">集合</param> /// <returns></returns> private static DataTable ToDataTableTow(IList list) { DataTable result = new…
本篇把项目中用到的一些通用方法总结出来, 这些方法因为经常需要在项目中用到,所以把它们归纳在一起, 形成一个.dll 文件是一个理想的选择. 这样也便于日后缩短开发周期. 一. 把一个DataGridView对象转换成一个DataTable对象 public static DataTable GetDgvToTable(DataGridView dgv)   {           if(dgv==null) throw new NullReferenceException();        …
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…