C# Insert ArrayList in DataRow

Go To StackoverFlow.com


I want to insert an arraylist in Datarow.

using this code,

      ArrayList array=new ArrayList();
      foreach (string s in array) 

But My datatable must have only one datarow. My code created eight datarows. I tried,


But it doesn't work.That should be


How can I solve this problem?


2012-04-03 23:14
by NoName
Your array has nothing in it, so of course indexing into it will fail. Put some data in the array variable first - debracey 2012-04-03 23:21
No...This code only for example.Array isn't empty.. - NoName 2012-04-03 23:41
C# is not Java. You should be using List<string>debracey 2012-04-04 01:37


try this:

        ArrayList array = new ArrayList();

        String[] arrayB = new String[array.Count];
        for (int i = 0; i < array.Count; i++)
            arrayB[i] = array[i].ToString();

2012-04-03 23:37
by John Woo
Excellent!.A) doesn't work.But B) fine...Thnk u - NoName 2012-04-03 23:52


try like this:

//1 - declare the array ArrayList object
ArrayList array = new ArrayList();

//2 - here add some elements into your array object

//3 - convert the ArrayList to string array and pass it as ItemArray to Rows.Add
2012-04-03 23:35
by Davide Piras