DataTable is Filled From DataSet each time a change is made

  • Thread starter Thread starter John Walsch
  • Start date Start date
J

John Walsch

Because I'm a beginner to ASP.NET, I may be not familiar with the way
each ASP.NET page is processed. In the books that I have read
(scanned), the purpose of DataSet is to keep your data in memory until
you decide to commit the changes. Ok, so I create and fill my DataSet
in the Page_Init section (I have tried in the Page_Load section as
well), and then later use one of the tables from the DataSet in the
DataGrid. But when I try to edit a row in the DataGrid (by pressing
the Edit link in the EditCommandColumn) a request is made back to the
server, thus reloading my page and reinitializing everything and
making a request to the database and FILLING my DataSet AGAIN. I mean
how is that different than just updating the database each time and
skipping few steps? Am I doing something wrong? From my understaning
it should reside in memory and not be reinitialized each time I make a
request to the page. What would I have to do in order to keep it in
memory and not reload it each time I make a request to the page? Would
I have to keep my DataSet object in the Session variable or something?

Thank you in advance.
 
One easy way to do this is to store it in Session state and use it from
there. When the page loads, hit the db and store it in session state or
cache it. After that (Page.IsPostBack) then just grap it from the Session
variable. If you aren' tfamiliar with them let me know (Session Variables).
In a desktop app you can just create a static/shared property of a class and
hold it there - but statics are shared across all users in ASP.NET so
everyone would be looking at the same data which wouldn't be good. When I
was first learning ASP.NET, I did this by mistake. Worked like a charm in
testing b/c there was only one user. Definitely a bad mistake to make on my
part.

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
Ok... That's what I assumed that the DataSet might have to be stored
in the Session Variable, though it didn't seem like a good way to do
it, since microsoft put in a lot of effort into this new feature in
ADO.NET so that you don't have to connect back to the database each
time you have a new change, but if you make a request back to the page
it all gets reloaded... In the books that I have looked at they don't
mention anything about session variables so that's why I wasn't sure
if thats a good way of doing it...

Is there another way?

I guess the session variable should be set to nothing once I'm done
with the DataSet (possibly in the destructor of the object that holds
my DataSet).

Thank You for your suggestion William. And if there are any other ways
of doing it I'd also would like to know about them since I'm not too
big on using Session variables (I'm not sure why).

Thanks again,
John
 
Back
Top