0

Here i am try to inserting Data into array,but here Iam getting bellow Error Object reference not set to an instance of an object. how can i insert Data into array using loop.

 String[][] data = new String[gvDetails.Rows.Count][];
               {
                    for (rowIndex = 0; rowIndex < gvDetails.Rows.Count; rowIndex++)
                    {
                        for (int k = 0; k < gvDetails.Columns.Count; k++)
                        {
                            string Data1=DataTable1.Rows[rowIndex][k].ToString();
                            data[rowIndex][k] = Data1;
}
}
User805
  • 113
  • 1
  • 1
  • 11
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – MakePeaceGreatAgain Jul 14 '16 at 10:16

1 Answers1

1

Each row in the jagged array is set to null initially and needs to be initialized:

for (rowIndex = 0; rowIndex < gvDetails.Rows.Count; rowIndex++)
{
    data[rowIndex] = new String[gvDetails.Columns.Count];
Andrei
  • 55,890
  • 9
  • 87
  • 108