from array to datatable

后端 未结 6 556
星月不相逢
星月不相逢 2021-01-02 06:26

ok i now it supose to be simple y have a multidimensional array, I try to fill my data table using the following code:

System.Data.DataTable _myDataTable =ne         


        
6条回答
  •  孤街浪徒
    2021-01-02 06:49

            var dt = new DataTable();
            var iFila = vals.GetLongLength(0);
            var iCol = vals.GetLongLength(1);
    
            for (var f = 1; f < iFila; f++)
            {
                var row = dt.Rows.Add();
                for (var c = 1; c <= iCol; c++)
                {
                    if (f == 1) 
                        dt.Columns.Add(vals[1, c] != null 
                            ? vals[1, c].ToString() 
                            : "");
    
                    row[vals[1, c].ToString()] = vals[f, c];
                }
            }
    

提交回复
热议问题