Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建一组字符串,列标题作为字符串标题,字符串值作为行0值_C#_Visual Studio 2010_Loops_Dataset - Fatal编程技术网

C# 创建一组字符串,列标题作为字符串标题,字符串值作为行0值

C# 创建一组字符串,列标题作为字符串标题,字符串值作为行0值,c#,visual-studio-2010,loops,dataset,C#,Visual Studio 2010,Loops,Dataset,我有第1栏第2栏和第3栏。在第0行中,这些值分别为1,2,3 我如何构建一个将设置的循环 string column 1 = 1 string column 2 = 2 string column 3 = 3 因此字符串名称是列标题,字符串的值是该列第0行中的值 这需要做大约150+列,我希望避免单独键入 列位于名为“ShipmentInfo”的表中。请尝试以下代码: for (int index = 0; index < DT.Rows.Count; index++) { f

我有第1栏第2栏和第3栏。在第0行中,这些值分别为1,2,3

我如何构建一个将设置的循环

string column 1 = 1
string column 2 = 2
string column 3 = 3 
因此字符串名称是列标题,字符串的值是该列第0行中的值

这需要做大约150+列,我希望避免单独键入

列位于名为“ShipmentInfo”的表中。

请尝试以下代码:

for (int index = 0; index < DT.Rows.Count; index++)
{
    foreach (DataColumn DC in DT.Columns)
    {
        DT.Rows[index][DC] = index;
    }
}
for(int index=0;index
这里DT是DataTable对象


希望这能对您有所帮助。

您使用什么控件制作这些列?为什么不能循环遍历列数组呢?我有一个填充的表,我希望根据表中的信息创建字符串。