Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to get large amount of data in datatable in asp.net mvc. the below code it's working but i need to show 1lac data in datatable. how can i get that without timeout problem and get data fastly.Plzz help me

What I have tried:

controller Page code:

C#
public ActionResult GetData()
     {
         string Constr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
         var source = new List<mng_industrymodel>();
         using (OdbcConnection conn = new OdbcConnection(Constr))
         {
             using (OdbcCommand cmd = new OdbcCommand("call pegasus_industry_select"))
             {
                 cmd.Connection = conn;
                 conn.Open();
                 cmd.CommandType = CommandType.StoredProcedure;
                 var dr = cmd.ExecuteReader();
                 while (dr.Read())
                 {
                     var orderlists = new mng_industrymodel
                     {
                         industry_Id = dr[0].ToString(),
                         industry_name = dr[1].ToString(),
                         industry_status = dr[2].ToString()
                     };
                     source.Add(orderlists);
                 }
                 return Json(new { data = source }, JsonRequestBehavior.AllowGet);
             }
         }

     }


view page code:



JavaScript
$(document).ready(function () {
    $('#tbltable').DataTable({
        "ajax": {
            "url": "/Management/GetData",
            "type": "GET",
            "datatype": "json"
        },
        "columns": [
            { "data": "industry_Id" },
            { "data": "industry_name" },
            { "data": "industry_status" },
            {
                "data": "industry_Id", "render": function (data) {

                    return "<a href='/Management/Edit/" + data + "' class='badge badge-success mb-1'><i class='far fa-edit p-1'></i> Edit</a><a href='' class='badge badge-danger' style='margin-left:5px' onclick=Delete('" + data + "')><i class='far fa-trash-alt p-1'></i> Delete</a>";
                },
                "orderable": false,
                "searchable": false,
                "width": "150px"

            }

        ]
    });
});
Posted
Updated 21-Feb-20 14:29pm
v3
Comments
Richard MacCutchan 21-Feb-20 4:22am    
How long would it take you to scroll through 100,000 items looking for the one you are interested in?

1 solution

Your problem isn't getting the data, that's easy - it's displaying it that takes time, and huge amounts of it. And you can't "work around" or "fix" that: if you are trying to throw a large amount of data at a user, you get a large amount of HTML, and that takes a lot of bandwidth, a lot of transfer time, and a lot of browser rendering.

Oh, and pissed off users because the site is both incredibly slow and unusable when it does finally load.

The solution is simple: don't throw so much data at a user. At most, 20 or 30 items at a time, with paging, searching, and filtering operations to make it easier for them to work with. Throw 1,000 items at a user and not only is the site slow, but the user can't find what he wants anyway. Think about it: a typical Google returns severy million hits - but you almost never go beyond page one. Instead, you change your search criteria to ring the info you wanted nearer to the top. Now imagine that google returned all 2,000,000 links every time you searched! We'd all use Bing instead ...
 
Share this answer
 
Comments
Member 14662237 21-Feb-20 5:24am    
using searching ,paging,filtering made it easier is it so????????reply me
OriginalGriff 21-Feb-20 5:31am    
It's more work for you - but that's what you get paid for - but it's quicker and much, much better for the user.

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