//先声明一个DataTable
DataTable dt = new DataTable();
//添加多个列,包括表头,以及数据类型
DataColumn dataColumnNum = new DataColumn(“列”, typeof(int));
DataColumn dataColumnX = new DataColumn(“X”, typeof(string));
DataColumn dataColumnY = new DataColumn(“Y”, typeof(string));
DataColumn dataColumnR = new DataColumn(“R”, typeof(string));
dt.Columns.Add(dataColumnNum);
dt.Columns.Add(dataColumnX);
dt.Columns.Add(dataColumnY);
dt.Columns.Add(dataColumnR);
//声明行
DataRow dtRow = null;
//对应列添加行,以下示例为添加一行的数据
dtRow = dt.NewRow();
dtRow[“列”] = 1;
dtRow[“X”] = “2”;
dtRow[“Y”] = “3”;
dtRow[“R”] = “4”;
dt.Rows.Add(dtRow);
DataTable添加数据
最新推荐文章于 2022-08-03 09:11:30 发布