Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to add a Table dynamically when the page is load with database table. But it's not working. Its give me a Exception:
An exception of type 'System.OutOfMemoryException' occurred in System.Web.dll but was not handled in user code

My Code:
C#
if (!IsPostBack == true)
            {
                System.Web.UI.WebControls.Login LoginControl = (System.Web.UI.WebControls.Login)PreviousPage.FindControl("Login1");
                if (LoginControl != null)
                {
                    TextBox UserName = (TextBox)LoginControl.FindControl("UserName");
                    if (UserName != null)
                    {
                        superEmail = UserName.Text.ToString();
                        //db.command.Parameters.Add("@SupervisorEmail", SqlDbType.VarChar).Value = superEmail.ToString();
                        //grdView.DataSource = db.Adapter("spVerify", true);
                        //grdView.DataBind();
                        lbl1.Text = superEmail.ToString();
                        db.command.Parameters.Add("@SupervisorEmail", SqlDbType.VarChar).Value = superEmail.ToString();
                        db.Adapter("spVerify", "okay", true);
                        for (int i = 0; i < db.dataSet.Tables["okay"].Rows.Count; i++)
                        {
                            TableRow tr = new TableRow();
                            for (int j = 0; j < 5; i++)
                            {
                                TableCell tc = new TableCell();
                                if(j == 0)
                                {
                                    tc.Text = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    tr.Cells.Add(tc);
                                }
                                if (j == 1)
                                {
                                    tc.Text = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    tr.Cells.Add(tc);
                                }
                                if (j == 2)
                                {
                                    tc.Text = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    tr.Cells.Add(tc);
                                }
                                if (j == 3)
                                {
                                    LinkButton link = new LinkButton();
                                    link.ID = "l" + i.ToString();
                                    link.Text = db.dataSet.Tables["okay"].Rows[0][4].ToString();
                                    link.EnableViewState = true;
                                    link.CommandName = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    link.Command += new CommandEventHandler(link_Command);
                                    //tc.Text = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    tc.Controls.Add(link);
                                    tr.Cells.Add(tc);
                                }
                                if (j == 4)
                                {
                                    tc.Text = db.dataSet.Tables["okay"].Rows[0][j].ToString();
                                    tr.Cells.Add(tc);
                                }
                            }
                            tbl.Rows.Add(tr);
                        }
                    }
                }
                else
                {
                    //Label1.Text = "Cannot find user name in Login control.";
                }
            }


Please help me.
Posted
Comments
Thomas Daniels 11-Feb-13 4:24am    
What's the row count?
Herman<T>.Instance 11-Feb-13 4:56am    
exactly. more than 200,000 rows can be problematic
Michael J. Eber 11-Feb-13 14:57pm    
Try to step through your code and follow the process. Frequently when I get an out of memory exception it is because I've inadvertantly triggered an event that loops back into my original code. As a result I have a sequence of <event> <load up="" stuff=""> <event is="" raised="" because="" i="" loaded="" stuff=""> <event> <load up="" stuff=""> ....

1 solution

There is not enough RAM on the server to handle your operation. Make the operation less memory consuming or add more memory to the server will solve the problem.
 
Share this answer
 
Comments
UL UL ALBAB 11-Feb-13 4:51am    
I am using 6 GB RAM with my Core"i5 Laptop. I think this not problem.
Marco Bertschi 11-Feb-13 4:55am    
Every application has (in Windows) a pool of memory assigned which is smaller than the total amount of memory available because there are always other memory-consuming applications running. This pool is usually only a few megabytes big within a DotNet app.... So the best way for you would be to make the operation less memory-consuming.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900