日期:2014-05-18 浏览次数:21042 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataTable dt = new DataTable(); DataColumn dc = new DataColumn("F1", typeof(System.String)); dt.Columns.Add(dc); dc = new DataColumn("F2", typeof(System.String)); dt.Columns.Add(dc); Console.WriteLine("DataTable创建完成时:"); for (int i = 0; i < dt.Columns.Count; i++) { Console.WriteLine(string.Format("第{0}列名称是:{1},列序号是:{2}", (i + 1).ToString(), dt.Columns[i].ColumnName, dt.Columns[i].Ordinal.ToString())); } Console.WriteLine("DataTable调整列位置之后:"); dc = dt.Columns[1]; dc.SetOrdinal(0); for (int i = 0; i < dt.Columns.Count; i++) { Console.WriteLine(string.Format("第{0}列名称是:{1},列序号是:{2}", (i + 1).ToString(), dt.Columns[i].ColumnName, dt.Columns[i].Ordinal.ToString())); } Console.Read(); } } }
------解决方案--------------------