Click here to Skip to main content
15,923,557 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionHow do i empty my DataSet? Pin
munklefish14-Apr-06 9:21
munklefish14-Apr-06 9:21 
AnswerRe: How do i empty my DataSet? Pin
Jakob Farian Krarup14-Apr-06 10:55
Jakob Farian Krarup14-Apr-06 10:55 
GeneralRe: How do i empty my DataSet? Pin
munklefish14-Apr-06 11:01
munklefish14-Apr-06 11:01 
GeneralRe: How do i empty my DataSet? Pin
Jakob Farian Krarup14-Apr-06 22:10
Jakob Farian Krarup14-Apr-06 22:10 
GeneralRe: How do i empty my DataSet? Pin
munklefish14-Apr-06 23:45
munklefish14-Apr-06 23:45 
GeneralRe: How do i empty my DataSet? Pin
Jakob Farian Krarup15-Apr-06 11:00
Jakob Farian Krarup15-Apr-06 11:00 
GeneralRe: How do i empty my DataSet? Pin
munklefish16-Apr-06 2:25
munklefish16-Apr-06 2:25 
GeneralRe: How do i empty my DataSet? Pin
Jakob Farian Krarup16-Apr-06 9:18
Jakob Farian Krarup16-Apr-06 9:18 
Hi Munklefish Smile | :)

Well, now that I've looked your code over again, it seems that you fill the DataTable with very different data for each request, based on the search being done. The method I was referring to is most useful if you have a couple of tables that very seldomly change, then you can load those into Applicationstate (a piece of RAM on the webserver that is shared between all users).

It would work something along the lines of (coding from memory here - might need a bit of IntelliSense later Roll eyes | :rolleyes: ):
protected void LoadData()
{
  //if we don't have any data in Application
  if(Application["myData"] == null)
  {
    //then we need to load it from the database
    //so we create a fresh dataset
    dsMyData = new DataSet();

    //and a new adapter for each of the tables we want in the dataset
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM orders", strConnectionString);
    //we fill the table
    adapter.Fill(sdMyData, "orders");
    //fill more tables as needed
    // .. etc ..
    // .. etc ..

    //Finally store the dataset in Application state
    Application["myData"] = dsMyData;
  }
  //otherwise, we have data in Application (from a previous call to the page)
  //and we just get a reference to the DataSet
  else
    dsMyData = (DataSet)Application["myData"];
}


This requires your connectionstring to be in the variable strConnectionString and a DataSet named csMyData to be declared on the Page level. Then you can call the LoadData method from the PageLoad eventhandler, and you will always have the tables in RAM, except for the first time of course. Application is emptied when the last users Session times out (by default 20 minutes after his/her last click on the page).

Since you actually don't need the DataTables in the code you showed me, then the DataReader is actually faster for just getting stuff from the DataBase. (also from memory ... don't hit me if it's not perfect!)
SqlConnection connection = new SqlConnection("server=(local);database=shop;user=me;password=secret");
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM orders WHERE ...yadayadayada...";
connection.Open();
dlOrders.DataSource = command.ExecuteReader();
dlOrders.DataBind();
connection.Close();


Hope this was of some use to you.


Kind regards - Jakob Cool | :cool:
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!

10 kinds of people in the world:
- Those who understand binary
- Those who don't
GeneralRe: How do i empty my DataSet? Pin
munklefish16-Apr-06 9:24
munklefish16-Apr-06 9:24 
GeneralRe: How do i empty my DataSet? Pin
Jakob Farian Krarup16-Apr-06 9:27
Jakob Farian Krarup16-Apr-06 9:27 
GeneralRe: How do i empty my DataSet? Pin
munklefish15-Apr-06 0:10
munklefish15-Apr-06 0:10 
GeneralRe: How do i empty my DataSet? Pin
Jakob Farian Krarup15-Apr-06 10:58
Jakob Farian Krarup15-Apr-06 10:58 
QuestionWeb Reference Error??? Pin
JimFeng14-Apr-06 8:53
JimFeng14-Apr-06 8:53 
QuestionProblems losing the state with SQL Session State in a Web Farm Pin
Albert Pascual14-Apr-06 7:26
sitebuilderAlbert Pascual14-Apr-06 7:26 
AnswerRe: Problems losing the state with SQL Session State in a Web Farm Pin
Mike Ellison14-Apr-06 10:47
Mike Ellison14-Apr-06 10:47 
GeneralRe: Problems losing the state with SQL Session State in a Web Farm Pin
Albert Pascual14-Apr-06 11:01
sitebuilderAlbert Pascual14-Apr-06 11:01 
Questionhow to display Windows form in ASP.NET 2.0 Pin
wasif_Muhammad14-Apr-06 7:18
wasif_Muhammad14-Apr-06 7:18 
AnswerRe: how to display Windows form in ASP.NET 2.0 Pin
Mike Ellison14-Apr-06 10:45
Mike Ellison14-Apr-06 10:45 
QuestionAutoPostBack on a Gridview Pin
Jason K14-Apr-06 6:58
Jason K14-Apr-06 6:58 
QuestionApplication_Error doesn't fire Pin
Dario Solera14-Apr-06 5:39
Dario Solera14-Apr-06 5:39 
AnswerRe: Application_Error doesn't fire Pin
Mike Ellison14-Apr-06 6:37
Mike Ellison14-Apr-06 6:37 
GeneralRe: Application_Error doesn't fire Pin
Dario Solera14-Apr-06 10:35
Dario Solera14-Apr-06 10:35 
QuestionEarly Page Timeout Pin
duncanthescott14-Apr-06 4:30
duncanthescott14-Apr-06 4:30 
AnswerRe: Early Page Timeout Pin
Mike Ellison14-Apr-06 6:44
Mike Ellison14-Apr-06 6:44 
GeneralRe: Early Page Timeout Pin
duncanthescott14-Apr-06 8:34
duncanthescott14-Apr-06 8:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.