Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am uploading an excel with data more than 2 lacs rows. Dividing into chunks of 500 rows everytime to create xml and hit the database , after processing using stored procedure i am returning the updated 500 rows and storing in a datatable and appending every 500 rows returned upto 2 lacs rows are processed.

Its working fine i get a datatable of 2 lacs processed rows. Now when i am reurning this Datatable to the View to display it throws Out Of Memory Exception.

Please help.

C#
Controller :

  return View(validateDS.Tables[0]);


View:

HTML
@model System.Data.DataTable
@using System.Data;

<h2>Upload File</h2>

@using (Html.BeginForm("Index", "Upload", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <div class="form-group">
        <input type="file" id="dataFile" name="upload" />
    </div>

    <div class="form-group">
       
        <input type="submit" name="Command" value="Upload Cegedim" class="btn btn-default" />
     
    </div>

    if (Model != null)
    {
        <table>
            <thead>
                <tr>
                    @foreach (DataColumn col in Model.Columns)
                    {
                        <th>@col.ColumnName</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (DataRow row in Model.Rows)
                {
                    <tr>
                        @foreach (DataColumn col in Model.Columns)
                        {
                            <td>@row[col.ColumnName]</td>
                        }
                    </tr>
                }
            </tbody>
        </table>
    }
}


What I have tried:

I have tried the above code. It worked fine for 50k records. now its not working for 2 lac records.

I know .Net provides only 2GB of data but there must be a work around for such situations Please help.


1) I also want to know how can i apply paging in this situation with the above code.
Posted
Updated 7-Sep-16 22:36pm
v3
Comments
Mehdi Gholam 8-Sep-16 2:55am    
Don't show so much data.
NaibedyaKar 8-Sep-16 3:09am    
I am not sure what kind of data you are showing, but 2 lacs records on a page is a very bad idea. You better look for server side paging to show data.
F-ES Sitecore 8-Sep-16 4:21am    
Please note this is an English language website, we don't know what "lacs" is, it doesn't mean anything to us so we don't know the numbers you're talking about.

Regardless, a human being can only process so much information anyway so showing a lot of data is always useless. Update your site to use paging\filtering\searching instead of just showing a massive list of data.
Abrar Kazi 8-Sep-16 7:30am    
ok thanks everyone i am applying paging

1 solution

The simple solution is: don't do it.
As has been mentioned, it's a bad idea. Why? Three reasons:
1) It's going to take a huge amount of bandwidth, and be very, very slow to display due the huge amount of data you are sending as the page.
2) Nobody if going to use it: most people won't even come back to the site a second time. Partly because it's so slow to load, but mostly because they can't find what they are looking for. Do you want to scroll though 200,000 rows looking for the row they are interested in? Even if they did, how long do you think it's going to take them?
3) It's going to crash out most browsers with an out of memory error, as you have seen - purely because the HTML it all generates is so damn huge.

Page it. Filter it. Let the user search it. But don't just dump it all on him and expect him to sort it out. That's the lazy way - easy for you, useless for the users. And that means it doesn't get used.
 
Share this answer
 
Comments
Abrar Kazi 8-Sep-16 7:30am    
Thanks
OriginalGriff 8-Sep-16 7:31am    
You're welcome!
Abrar Kazi 8-Sep-16 8:12am    
Please look into this.

http://www.codeproject.com/Questions/1125954/Model-becomes-empty-on-pagedlist-nd-page-click

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