Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2004, 04:10 PM
Authorized User
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Scope of a Dataset

hi all,

I am having a problem with datasets. My understanding was that if a dataset was defined as a member of a class and if it was populated in one of the events then the populated dataset should be available in any of the other events of the same class.

But this is not happenning. As soon as the code for the event in which the dataset is being populated is executed I observed that the dataset becomes empty. Why is this happenning?

Can anyone please tell me why?

Thanks in advance,
Qadeer


 
Old April 16th, 2004, 04:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Qadeer,

Can you post the relevant parts of your code? It depends on how you designed and use your class whether the DataSet will contain valid data or not.
It's hard to tell without seeing some of the code.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Straight Ahead, Then Take the Next Wrong / Two Right Wrongans by Terry Francis (Track 11 from the album: Architecture)

 
Old April 16th, 2004, 05:26 PM
Authorized User
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks for your reply... Here is a basic structure of my code (The complete code is very long so I decided to put a simplified structure similar to my code)

In the code below 'dsPopulateGrid1.Tables["Table1"].Select()' in the button click event returns 0 rows. Where as if the same code is pasted in page load it returns a the number of rows in 'Table1'.

namespace NewVaccineSelection
{
    public class algorithm : System.Web.UI.Page
    {
        -
        -
        protected dsPopulateGrid dsPopulateGrid1 = new dsPopulateGrid();
        -
        -
                private void Page_Load(object sender, System.EventArgs e)
        {
            -
            -
                    this.sqlConn.Open();
            sqlDAPopulateGrid.Fill(this.dsPopulateGrid1,"Table 1");
            this.sqlConn.Close();
            -
            -
                }
                private void Button_Click(object sender, System.EventArgs e)
        {
            -
            -
                    DataRow[] row_array = dsPopulateGrid1.Tables["Table1"].Select();
            -
            -
                 }
    }
}

 
Old April 16th, 2004, 06:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I am not sure what kind of object dsPopulateGrid is, but apparently it does not maintain its state during postbacks.
This means that when you post back (e.g.) click the Button, you'll loose the value of that variable.
You probably need to recreate the DataSource / object again after postback. You can do this by calling a custom method from the Page_Load event.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Pop Song For Us Rejects by Silverchair (Track 8 from the album: Freak Show)

 
Old April 19th, 2004, 08:00 AM
Authorized User
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar..

dsPopulateGrid is a dataset and does a dataset loose its state after postback??

Qadeer

 
Old April 19th, 2004, 08:12 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, it does. A DataSet is not a Web Control, so it has no means of maintaining state.

If you bind a DataSet to a control, that control may be able to maintain its state (depends on the control and the settings you have applied to it), but the DataSet just disappears after the page has loaded, rather like other variables like a string or an int.

Usually, a DataSet is recreated after important actions on the page, like Edit, Delete etc and then rebound to the control.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: One Of Us by ABBA (Track 16 from the album: Gold - Greatest Hits)

 
Old April 19th, 2004, 09:09 AM
Authorized User
 
Join Date: Apr 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
Thank you very much for clarifying that for me. You've been very helpful.
Qadeer






Similar Threads
Thread Thread Starter Forum Replies Last Post
Scope of Objects Handman BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 12 October 20th, 2008 10:06 AM
Scope Issue iceman90289 C# 2005 8 April 5th, 2008 03:41 PM
what is the scope of PHP raaj Beginning PHP 1 February 13th, 2007 12:51 AM
the scope of variable ccj_999 C++ Programming 9 October 26th, 2006 10:35 AM
DataSet Scope jbenson001 ASP.NET 1.x and 2.0 Application Design 2 December 5th, 2003 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.