0
votes

I am taking the data into a 2d string in C#. Defined as ::

string[,] strValueBasic = new string[GridView1.Rows.Count,49];

Now i want the data to be taken into DataRows and add these rows into the DataTable.

     for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    DataRow drRow = dtNew.NewRow();
                    drRow.ItemArray = strValueBasic[i];
                    dtNew.Rows.Add(drRow);
                }

But i am not able to access this 2d String array in the step

                    drRow.ItemArray = strValueBasic[i];

It is giving error as Wrong number of indices inside [], expected 2.

I know that it requires 2 indices, but than i want the whole row of that string array to be filled inside that DataRow.

Also the structure of DataRow and String Array is same.

2

2 Answers

1
votes

If you want to assign whole row your strValueBasic should be defined as string[][]. Not the 2D array but array of arrays. That changes initialization too, each array can have different size so you have to create each separately. http://msdn.microsoft.com/en-us/library/2s05feca.aspx

0
votes

Thats because strValueBasic is a 2D array and you're trying to access it as it's a 1D array.

 for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                DataRow drRow = dtNew.NewRow();
                drRow.ItemArray = strValueBasic[i, iSomeOtherValue];
                dtNew.Rows.Add(drRow);
            }

Notice iSomeOtherValue, you're missing something!