1

I have following code:

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
    for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
    {
        strCsv.Append( XC.CleanForCsv(ds.Tables[0].Rows[i][j].ToString()) + ",");
    }

    strCsv.Append( "\r\n" + strCsv)
}

Dataset contains 8000 records. Looping through the records using a for loop after only 15 records strCsv.Append( "\r\n" + strCsv) statement throws an exception saying System.OutOfMemoryException. What is the reason behind this exception?

1
  • 1
    Note for future questions - please pay more attention to formatting your code nicely. I'll edit the question now to show how it should have been posted to start with, but please do it on your initial post in future. Commented Jul 30, 2013 at 7:18

1 Answer 1

13

Look at this:

strCsv.Append( "\r\n" + strCsv)

You're doubling the output on every iteration. That will build up very quickly - as well as giving you the wrong results.

I think you just want:

strCsv.Append("\r\n");
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.