创建datatable
时间:2011-05-27 来源:解磊
private DataTable CreateTable()
{
DataTable dt = new DataTable("dirName");
#region table column
DataColumn columnID = new DataColumn(); //创建一列
columnID.DataType = System.Type.GetType("System.Int32"); //数据类型
columnID.ColumnName = "ID"; //列名
columnID.AutoIncrement = true; //自动递增ID号
dt.Columns.Add(columnID); //添加到table 本文来自织梦
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.ColumnName = "Name";
dt.Columns.Add(columnName);
DataColumn fullName = new DataColumn();
fullName.DataType = System.Type.GetType("System.String");
fullName.ColumnName = "fullName";
dt.Columns.Add(fullName);
DataColumn cTime = new DataColumn(); 本文来自织梦
cTime.DataType = System.Type.GetType("System.String");
cTime.ColumnName = "CreateDate";
dt.Columns.Add(cTime);
DataColumn type = new DataColumn();
type.DataType = System.Type.GetType("System.String");
type.ColumnName = "type";
dt.Columns.Add(type);
DataColumn exName = new DataColumn();
exName.DataType = System.Type.GetType("System.String");
//基于所有创建的数据库架构添加行
DataRow newRow;//声明一个新行
newRow = tblBugs.NewRow();
newRow["Product"] = 1;
newRow["Version"] = "0.1";
newRow["Description"] = "Crashes on load";
newRow["Reporter"] = 5;
tblBugs.Rows.Add(newRow);
newRow = tblBugs.NewRow();
newRow["Product"] = 1;
newRow["Version"] = "0.1";
newRow["Description"] = "Does not report correct owner of bug";
newRow["Reporter"] = 5;
tblBugs.Rows.Add(newRow);