DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("no",Type.GetType("System.Int32")),
new DataColumn("name",Type.GetType("System.String")),
new DataColumn("age",Type.GetType("System.Int32")),
new DataColumn("score",Type.GetType("System.Int32")),
}
);
DataTable dtmoney = new DataTable();
dtmoney.Columns.AddRange(new DataColumn[]
{
new DataColumn("no",Type.GetType("System.Int32")),
new DataColumn("money",Type.GetType("System.Decimal")),
}
);
int[] nolist = { 1,2,3,4,5};
string[] namelist = {"zhang","wang","qian","li","sun" };
int[] age = { 20,21,19,22,20};
int[] score = { 100,90,80,80,70};
Decimal [] moneylist = { 400.23m, 324.32m, 303.42m,230m,399.1m };
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["no"] = nolist[i];
dr["name"] = namelist[i];
dr["age"] = age[i];
dr["score"] = score[i];
dt.Rows.Add(dr);
DataRow drmoney = dtmoney.NewRow();
drmoney["no"] = nolist[i];
drmoney["money"] = moneylist[i];
dtmoney.Rows.Add(drmoney);
}
本文转自cnn23711151CTO博客,原文链接: http://blog.51cto.com/cnn237111/472406,如需转载请自行联系原作者