Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:32:37+00:00 2026-06-17T21:32:37+00:00

I have a DataTable which I fill from a database and the in code

  • 0

I have a DataTable which I fill from a database and the in code behind I am trying to add 3 more rows after each row. Below is the code. But at the 6th line I get

Exception of type ‘System.OutOfMemoryException’ was thrown.

  for (int i = 0; i < AlldaysList.Rows.Count; i++)
    {
        DataRow row;
        row = AlldaysList.NewRow();
        DataRow row1;
        row1 = AlldaysList.NewRow();
        DataRow row2;
        row2 = AlldaysList.NewRow();

        // Then add the new row to the collection.
        row["scenarionid"] = DBNull.Value;
        row["description"] = "";
        row1["scenarionid"] = DBNull.Value;
        row1["description"] = "";
        row2["scenarionid"] = DBNull.Value;
        row2["description"] = "";
        AlldaysList.Rows.InsertAt(row, i + 1);
        AlldaysList.Rows.InsertAt(row1, i + 2);
        AlldaysList.Rows.InsertAt(row2, i + 3);
        i++;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:32:38+00:00Added an answer on June 17, 2026 at 9:32 pm
    //This could be the problem
    i < AlldaysList.Rows.Count
    

    i think u should have a variable called int rowCount = AlldaysList.Rows.Count; before the loop..

    the loop should be  for (int i = 0; i < rowCount; i++)
    

    The reason why i say this is because if u add 3 rows inside the loop ur AlldaysList.Rows.Count is changing by +3 and u r targeting a dynamic variable instead of a static one and so it goes into the loop again and causes an exception..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTable which I select from database (Well, these data cross several
I have a GridView1 , which I am binding from code behind. The one
I have a DataTable which I want to save to a SQLite Database Table.
I have a datatable on which I am applying Select() method. After that I
I am connecting C# with Oracle 11g. I have a DataTable which i fill
I have a page with datatable with product information from which at a product
I have this function of mine which selects all room types from the database,
I am trying to retrieve some rows from the database using simple SELECT statement
I have the following code which executes a custom query to the database. The
I have a datatable which contains yearly data saved. e.g. dtDate Value 2010-01-01 00:00:00.000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.