首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

运用循环创建table表的列

2013-08-16 
使用循环创建table表的列for (int i 0 i 15 i++){dt.Columns.Add(new DataColumn(i typeof(Int32))

使用循环创建table表的列
for (int i = 0; i < 15; i++)
{
    dt.Columns.Add(new DataColumn(i; typeof(Int32)));
}
这样子好像有错误,怎么能使列名用i代替
[解决办法]
变通一下:

string[] str = new string[] { "dt1", "dt2", "dt3", "dt4", "dt5" };
            DataTable dt = new DataTable();
            foreach (string item in str)
            {
                dt.Columns.Add(item, typeof(Int32));
            }


[解决办法]
dt.Columns.Add(new DataColumn(i.toString(); typeof(Int32)));

热点排行