using System;using System.Collections.Generic;using System.Data;using System.Text; namespace Gzcms.Common{ public class CreateTable { public static DataTable getTable() { //1.创建 datatable DataTable dt = new DataTable("datatable");//可以给表创建一个名字datatable //2.给表加个列名: dt.Columns.Add("id", typeof(System.Int32));//类型是可以变换的,比如System.Int32,System.Double.. dt.Columns.Add("title", typeof(System.String)); //3.给表加行,内容: DataRow row = dt.NewRow(); row["id"] = 1; row["title"] = "标题1"; dt.Rows.Add(row);//这样就可以添加了 row = dt.NewRow(); row["id"] = 2; row["title"] = "标题2"; dt.Rows.Add(row); return dt; } } }