DataTable tblDatas = new DataTable("Datas");
tblDatas.Columns.Add("ID", Type.GetType("System.Int32"));
tblDatas.Columns[0].AutoIncrement = true;
tblDatas.Columns[0].AutoIncrementSeed = 1;
tblDatas.Columns[0].AutoIncrementStep = 1;//自增列
tblDatas.Columns.Add("Product", Type.GetType("System.String"));
tblDatas.Columns.Add("Version", Type.GetType("System.String"));
tblDatas.Columns.Add("Description", Type.GetType("System.String"));
DataRow row;
for (int i = 0; i <= 3; i++)
{
row = tblDatas.NewRow();
row["Product"] = "789";
row["Version"] = "Item ";
row["Description"] = "567";
tblDatas.Rows.Add(row);
}foreach (DataRow dr in tblDatas.Rows)
{
Response.Write(dr["Version"].ToString() + "<br/>");
}
datatable动态添加,及填充数据
时间: 2024-10-29 15:40:33