Large DataSets and GridView Problems displaying data more than once!

Discussion in 'ASP .Net' started by Dave, Jul 12, 2008.

  1. Dave

    Dave Guest

    I'm having problems getting the GridView to reliably display a large
    amount of data (50,000+ rows).

    I am working my way through the excellent book “Real World ASP.NET
    Best Practices” by Farhan Muhammad. In some cases I’m trying to
    extend the examples.
    Currently, I have the following code to read data from a SQL Server
    2005 database and display in a GridView:


    DataSet MyDataSet = new DataSet();
    SqlDataAdapter MyAdapter = new SqlDataAdapter();
    SqlCommand MyCommand = new SqlCommand();
    MyCommand.Connection = new SqlConnection(MyConnection);
    MyCommand.CommandText = " select * from Table_1";

    MyAdapter.SelectCommand = MyCommand;
    MyCommand.Connection.Open();
    MyAdapter.Fill(MyDataSet);

    GridView1.DataSourceID = "";
    GridView1.DataSource = MyDataSet.Tables[0].DefaultView;
    GridView1.DataBind();
    MyCommand.Connection.Close();
    MyCommand.Dispose();

    I created Table_1. It’s just a list of firstnames, lastnames. The code
    works the first time and the GridView displays the 50,000 data. But
    when I hit the button again, I get “Internet Explorer cannot display
    the webpage”. I’ve verified that the first line of code is not even
    hit AND SQL Profiler shows no database activity. What’s going on?
    I’d be the first to admit, that one would not normally have a table
    with 50,000+ records, and want to display all of the records (no
    filter!) in a GridView, but I’d still like to know what is going on.

    Incidentally, the original exercise (from Ch.2 of the book) searched
    for a specific record with:
    MyCommand.CommandText = " select * from Table_1 where firstname = '" +
    txtFirstName.Text + "' ";

    The point of the exercise was to show that it was faster to go
    directly to the database rather than hit cache. I found this to be
    true if one used the binding methods suggested by the authors:

    DataSet MyDataSet = Cache["Result"] as DataSet;
    DataView MyDataView = new DataView(MyDataSet.Tables[0]);
    MyDataView.RowFilter = "firstname = '" + txtFirstName.Text + "' ";
    GridView1.DataSourceID = "";
    GridView1.DataSource = MyDataView;
    GridView1.DataBind();

    However, if one uses the following:

    DataSet MyDataSet = Cache["Result"] as DataSet;
    DataSet newDataSet = new DataSet();
    newDataSet.Merge(MyDataSet.Tables[0].Select("firstname = '" +
    txtFirstName.Text + "' "));
    GridView1.DataSourceID = "";
    GridView1.DataSource = newDataSet.Tables[0].DefaultView;
    GridView1.DataBind();

    Then, going to cache is faster than going to the database.
    Admittedly, this idea of Merging datasets may not have existed when
    the book was written (2003), and/or I’ve missed something important.
    Opinions?

    Thanks,


    Dave
    Dave, Jul 12, 2008
    #1
    1. Advertising

  2. Dave

    Munna Guest

    Re: Large DataSets and GridView Problems displaying data more thanonce!

    Hi,,,

    First of all 50,000 row in a single page.... not seems to be very
    helpfull...
    To create 50000 row at once will add huge amount of html markup in
    page...

    I would better do a paged view of the data ... and make sure that i
    only
    fetch only the data of the current page...

    http://www.codeproject.com/KB/aspnet/PagingGridView.aspx

    Best of luck

    -----------
    Munna

    www.munna.shatkotha.com/blog
    www.munna.shatkotha.com
    www.shatkotha.com
    Munna, Jul 12, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    24
    Views:
    1,688
    alchemist
    Aug 4, 2005
  2. Superman
    Replies:
    0
    Views:
    285
    Superman
    Feb 27, 2007
  3. Gancy
    Replies:
    4
    Views:
    176
    Rasto Levrinc
    Feb 3, 2005
  4. Steven D'Aprano
    Replies:
    0
    Views:
    90
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    82
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page