添加table

来源:互联网 发布:我的世界网络mod 编辑:程序博客网 时间:2024/05/23 20:19
 private static DataTable CreateWords4Table()        {            string[] words = { "blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese" };            DataTable table = new DataTable("Words4");            table.Columns.Add("word", typeof(string));            foreach (string word in words)            {                table.Rows.Add(new object[] { word });            }            return table;        }




static void Main(string[] args)        {            System.Data.DataTable table = new System.Data.DataTable("TB");            table.Columns.Add("Id", typeof(Int32));            table.Columns.Add("Name", typeof(string));            for (int i = 0; i < 5; i++)            {                 table.Rows.Add(new object[]{i,"aa"+i});            }            StringBuilder sb = new StringBuilder();            foreach (DataRow row in table.Rows)            {                 foreach(DataColumn columns in table.Columns)                {                    Console.Write("{0}:{1}",columns.ColumnName,row.IsNull(columns)?"Null":row[columns]);                }            }            //Console.WriteLine();            //string str = "123456";            //str = str.Substring(0,5);            //Console.WriteLine(str);            //Console.WriteLine(DateTime.Today+"====="+DateTime.Now);            //for (int i = 0; i < table.Rows.Count; i++)            //{            //    Console.Write(table.Rows[i]["Id"].ToString()+table.Rows[i]["Name"]);            //}        }


0 0
原创粉丝点击