Two dimensional Array into DataTable


string  [,] mdArray = new string  [3,3]{{"a","b","c"},{"d","e","f"},{"g","h","i"}};
       ArrayList arList = new ArrayList();
        DataTable table = new DataTable();
       table.Columns.Add("C1");
       table.Columns.Add("C2");
       table.Columns.Add("C3");


       //Multi Dimension Array into DataTable
       for (int outerIndex = 0; outerIndex < 3; outerIndex++)
       {
             DataRow newRow = table.NewRow();
           for (int innerIndex = 0; innerIndex < 3; innerIndex++)
           {


               newRow[innerIndex] = mdArray[outerIndex,innerIndex ];
               

           }
           table.Rows.Add(newRow);
       }


       //Multi Dimension Array into ArrayList ( ArrayList of ArrayList)
       for (int outerIndex = 0; outerIndex < 3; outerIndex++)
       {
           ArrayList innerList = new ArrayList();
           for (int innerIndex = 0; innerIndex < 3; innerIndex++)
           {


               innerList.Add(mdArray[outerIndex, innerIndex]);


           }
           arList.Add(innerList);
       }



reference:
http://forums.asp.net/t/1440568.aspx/1

Comments

Popular posts from this blog

like php