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;
}
}
1

1 Answer 1

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.