Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 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 February 2nd, 2006, 12:44 PM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default Can we use same Dataset Object?

Hello Friends,
Throughout the application(ASP.NET and VB.NET),how can we use same dataset and its tables?I mean to say that dataset is created when HomePage is loaded.Can we use the contents of this dataset in all the pages of the website? If your answer is yes,how can this be done?

Thank you. friends,I am waiting for some kind replies.


Gaurav

__________________
Gaurav
 
Old February 2nd, 2006, 03:51 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

If you want to use the data retrieved in the page load all over the app, you have to set it into a session variable. Then to retrive it, you neet to convert the session var to your ds object.

'set the session var
Session("ds") = yourdataset

'retrieve the session var
dim ds as new dataset
ds = CType(session("ds"),yourdataset)

Jim



 
Old February 3rd, 2006, 12:06 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Thank you Jim.
Yes, you are right. We can do this by using Session. But Cannot we do this by declaring a variable of datatype DATASET in global.asax and then storing our dataset in this variable and using it throughout the application. I am not sure if it can be done or not..... so please guide me .

Thanks again


Gaurav

 
Old February 3rd, 2006, 12:23 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

This is from VS Help:

This example loads a dataset and stores it in application state so that it is available to all Web Forms pages and other processes in the Web application. The event fires when the application runs the first time (when the first user gets the first page of the application after the Web server is active).

Example
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    SqlDataAdapter1.Fill(DsRegion1)
    Application("dsRegion") = DsRegion1
End Sub
Compiling the Code
This example requires:

A Web application with a Global.asax file. The Application_Start handler is created in the Global.asax file.
A data connection configured to connect to the SQL Server Northwind database.
A typed dataset named dsRegion1, which is an instance of the typed dataset class dsRegion. For details, see Creating Typed Datasets with the Component Designer.
A data adapter called SqlDataAdapter1 configured to read information from the Northwind Region table.
Note If you open the Global.asax file in the Web Forms designer, you can drag data components onto it just as you would onto a Web Forms page.
The application must have permission to access the database. For details, see Access Permissions for Web Applications.
After this event handler has run, any page or component in the application has access to the information. For example, a Web Forms page can get access to the Region table without having to connect to the database and query it. The Web Forms page might include code such as the following to get the table and make it available for data binding:

Private Sub Page_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
    DsRegion1 = CType(Application("dsRegion"), dsRegion)
    DataGrid1.DataBind()
End Sub
 
Old February 3rd, 2006, 01:09 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Thank you again Jim.
In my application, I want user to enter his login_ID and password. Then, this information will be send to the database and if it matches, the corresponding row will be stored in the Dataset and the user will be redirected to the new page. Now, I want to use this row(containing all user information) in dataset in all the pages. I think Using Global.asax is not a correct solution to it. So, what should i prefer to use in my home page?session state or application state.
 
Old February 3rd, 2006, 01:22 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

If you are storing user data then use session state.

 
Old February 3rd, 2006, 01:49 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Thanks Jim.
I hope my problem has been sorted out. I will try this in my application. Have a nice time ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill(dataset) or dataset.load() salemkoten SQL Server 2005 1 November 2nd, 2006 11:04 PM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM
Newbie who needs help with DataSet object!!! rboyle ADO.NET 1 March 10th, 2004 08:25 PM





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