473,651 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Session.add() with ado

Hello!,

I have a using system.web.sess ionstate directive one the top of each of two
web pages. On the first page I have the dataadapter, dataconnection, and
dataset (also in the component tray). I have used Session.Add().

Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

On the other page I have used a cast to get at the Session objects that I
supposedly stored on the other page.

SqlDataAdapter da2 =
(System.Data.Sq lClient.SqlData Adapter)Session["dadapter"]);

Dataset ds2 = (System.Data.Da taSet)Session["dset"]);

My code on the page where I want to use the data from the database(The other
page has the ADO in the component tray) says

Session("dadapt er")=null
Session("dset") =null

I looked through the MSDN to see if I could get some error messages out of
the session object, but no go. As far as the ASP.NET I get the error "object
reference not set to an instance of an object." What could be wrong?
--
Spencer
Nov 19 '05 #1
7 2554
Basically,

You just held the variable names in session state not the objects itselves.
So, to create the objects after you cast each variable reference out you
should do a
da2 = new SqlDataAdapter( );
ds2 = new Dataset():

This should allow you to use these objects.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in message
news:BE******** *************** ***********@mic rosoft.com...
Hello!,

I have a using system.web.sess ionstate directive one the top of each of
two
web pages. On the first page I have the dataadapter, dataconnection, and
dataset (also in the component tray). I have used Session.Add().

Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

On the other page I have used a cast to get at the Session objects that I
supposedly stored on the other page.

SqlDataAdapter da2 =
(System.Data.Sq lClient.SqlData Adapter)Session["dadapter"]);

Dataset ds2 = (System.Data.Da taSet)Session["dset"]);

My code on the page where I want to use the data from the database(The
other
page has the ADO in the component tray) says

Session("dadapt er")=null
Session("dset") =null

I looked through the MSDN to see if I could get some error messages out of
the session object, but no go. As far as the ASP.NET I get the error
"object
reference not set to an instance of an object." What could be wrong?
--
Spencer

Nov 19 '05 #2
My code still says the session state for the two variables I stored on the
other page is equal to null. I set the da2, and ds2 equal to new
Sqldataadapter and new Dataset.The error says "The SelectCommand property has
not been initialized before calling Fill." Should I import into session state
the Select, Insert, Update, and Delete commands also? Would it be easier to
just use the sql wizard and generate the ado statements on both pages? Thanks.

Spencer

"Tampa.NET Koder" wrote:
Basically,

You just held the variable names in session state not the objects itselves.
So, to create the objects after you cast each variable reference out you
should do a
da2 = new SqlDataAdapter( );
ds2 = new Dataset():

This should allow you to use these objects.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in message
news:BE******** *************** ***********@mic rosoft.com...
Hello!,

I have a using system.web.sess ionstate directive one the top of each of
two
web pages. On the first page I have the dataadapter, dataconnection, and
dataset (also in the component tray). I have used Session.Add().

Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

On the other page I have used a cast to get at the Session objects that I
supposedly stored on the other page.

SqlDataAdapter da2 =
(System.Data.Sq lClient.SqlData Adapter)Session["dadapter"]);

Dataset ds2 = (System.Data.Da taSet)Session["dset"]);

My code on the page where I want to use the data from the database(The
other
page has the ADO in the component tray) says

Session("dadapt er")=null
Session("dset") =null

I looked through the MSDN to see if I could get some error messages out of
the session object, but no go. As far as the ASP.NET I get the error
"object
reference not set to an instance of an object." What could be wrong?
--
Spencer


Nov 19 '05 #3
Ah, you didn't get the same error. Thats a start. Grant it, I don't like
the way you are doing this but I'm sure you can get this to work. Try
posting some code, so we can see what you have already. Maybe there is
something that is missing. Using the data tool is OK, only for beginners.
The more you start to use this stuff, you will see that the data tools
binded to each page will be harder to maintain.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
My code still says the session state for the two variables I stored on the
other page is equal to null. I set the da2, and ds2 equal to new
Sqldataadapter and new Dataset.The error says "The SelectCommand property
has
not been initialized before calling Fill." Should I import into session
state
the Select, Insert, Update, and Delete commands also? Would it be easier
to
just use the sql wizard and generate the ado statements on both pages?
Thanks.

Spencer

"Tampa.NET Koder" wrote:
Basically,

You just held the variable names in session state not the objects
itselves.
So, to create the objects after you cast each variable reference out you
should do a
da2 = new SqlDataAdapter( );
ds2 = new Dataset():

This should allow you to use these objects.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in
message
news:BE******** *************** ***********@mic rosoft.com...
> Hello!,
>
> I have a using system.web.sess ionstate directive one the top of each of
> two
> web pages. On the first page I have the dataadapter, dataconnection,
> and
> dataset (also in the component tray). I have used Session.Add().
>
> Session.Add("da dapter", sqlDataAdapter1 );
> Session.Add("ds et", ds);
>
> On the other page I have used a cast to get at the Session objects that
> I
> supposedly stored on the other page.
>
> SqlDataAdapter da2 =
> (System.Data.Sq lClient.SqlData Adapter)Session["dadapter"]);
>
> Dataset ds2 = (System.Data.Da taSet)Session["dset"]);
>
> My code on the page where I want to use the data from the database(The
> other
> page has the ADO in the component tray) says
>
> Session("dadapt er")=null
> Session("dset") =null
>
> I looked through the MSDN to see if I could get some error messages out
> of
> the session object, but no go. As far as the ASP.NET I get the error
> "object
> reference not set to an instance of an object." What could be wrong?
> --
> Spencer


Nov 19 '05 #4
Web page 2 (aspx)

sqldataadapter da2 = (system.data.sq lclient.sqldata adapter)session["dadapter"]
dataset ds2 = (system.data.da taset)session["dset"]
da2 = new sqldataadapter( )
ds2 = new dataset()
da2.fill(ds2)
Web page(aspx) with ado.net in component tray

Session.add("da dapter", sqldataadapter1 );
Session.add("ds et", ds);

The ado.net error from the fill statement is:

"The SelectCommand property has not been initialized before calling 'Fill'

I suppose I could add the the rest of the ado to the session state, but I am
not sure if it is necessary or not. Thanks for your help.

Spencer

"Tampa.NET Koder" wrote:
Ah, you didn't get the same error. Thats a start. Grant it, I don't like
the way you are doing this but I'm sure you can get this to work. Try
posting some code, so we can see what you have already. Maybe there is
something that is missing. Using the data tool is OK, only for beginners.
The more you start to use this stuff, you will see that the data tools
binded to each page will be harder to maintain.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
My code still says the session state for the two variables I stored on the
other page is equal to null. I set the da2, and ds2 equal to new
Sqldataadapter and new Dataset.The error says "The SelectCommand property
has
not been initialized before calling Fill." Should I import into session
state
the Select, Insert, Update, and Delete commands also? Would it be easier
to
just use the sql wizard and generate the ado statements on both pages?
Thanks.

Spencer

"Tampa.NET Koder" wrote:
Basically,

You just held the variable names in session state not the objects
itselves.
So, to create the objects after you cast each variable reference out you
should do a
da2 = new SqlDataAdapter( );
ds2 = new Dataset():

This should allow you to use these objects.
"Spencer H. Prue" <Sp**********@d iscussions.micr osoft.com> wrote in
message
news:BE******** *************** ***********@mic rosoft.com...
> Hello!,
>
> I have a using system.web.sess ionstate directive one the top of each of
> two
> web pages. On the first page I have the dataadapter, dataconnection,
> and
> dataset (also in the component tray). I have used Session.Add().
>
> Session.Add("da dapter", sqlDataAdapter1 );
> Session.Add("ds et", ds);
>
> On the other page I have used a cast to get at the Session objects that
> I
> supposedly stored on the other page.
>
> SqlDataAdapter da2 =
> (System.Data.Sq lClient.SqlData Adapter)Session["dadapter"]);
>
> Dataset ds2 = (System.Data.Da taSet)Session["dset"]);
>
> My code on the page where I want to use the data from the database(The
> other
> page has the ADO in the component tray) says
>
> Session("dadapt er")=null
> Session("dset") =null
>
> I looked through the MSDN to see if I could get some error messages out
> of
> the session object, but no go. As far as the ASP.NET I get the error
> "object
> reference not set to an instance of an object." What could be wrong?
> --
> Spencer


Nov 19 '05 #5
Hi Spencer,

Before you use SessionState to hold an object, you should
initialize it. Otherwise you only hold a null value in
SessionState. For example, you should do it like following:

SqlDataAdapter sqlDataAdapter1 = New SqlDataAdapter
(sqlQuery, connction);
DataSet ds = new DataSet();
sqlDataAdapter1 .Fill(ds);
Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

HTH

Elton Wang
el********@hotm ial.com
-----Original Message-----
Hello!,

I have a using system.web.sess ionstate directive one the top of each of twoweb pages. On the first page I have the dataadapter, dataconnection, anddataset (also in the component tray). I have used Session.Add().
Session.Add("d adapter", sqlDataAdapter1 );
Session.Add("d set", ds);

On the other page I have used a cast to get at the Session objects that Isupposedly stored on the other page.

SqlDataAdapt er da2 =
(System.Data.S qlClient.SqlDat aAdapter)Sessio n ["dadapter"]);
Dataset ds2 = (System.Data.Da taSet)Session["dset"]);

My code on the page where I want to use the data from the database(The otherpage has the ADO in the component tray) says

Session("dadap ter")=null
Session("dset" )=null

I looked through the MSDN to see if I could get some error messages out ofthe session object, but no go. As far as the ASP.NET I get the error "objectreference not set to an instance of an object." What could be wrong?--
Spencer
.

Nov 19 '05 #6
Thanks for the help Elton,

I used the sqldataadapterw izard to generate the statements that were needed
for the ado. I know it's a shortcut, but the wizard said all the statements
were generated correctly. It left a protected
system.data.sql client.sqldataa dapter sqldataadapter1 statement in the wizard
generated code. I just filled the dataset with it, I didn't bother with new.
It appears to be working correctly. I also used it to do an update.

So from what the wizard generated I just added it to the session. Do you
think I should try a new sqldatadapter before the session.add? I am not sure
how to create a connection string and the sql statements. As I said, I think
the wizard did everything for me. Thanks

Spencer
"Elton Wang" wrote:
Hi Spencer,

Before you use SessionState to hold an object, you should
initialize it. Otherwise you only hold a null value in
SessionState. For example, you should do it like following:

SqlDataAdapter sqlDataAdapter1 = New SqlDataAdapter
(sqlQuery, connction);
DataSet ds = new DataSet();
sqlDataAdapter1 .Fill(ds);
Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

HTH

Elton Wang
el********@hotm ial.com
-----Original Message-----
Hello!,

I have a using system.web.sess ionstate directive one the

top of each of two
web pages. On the first page I have the dataadapter,

dataconnection, and
dataset (also in the component tray). I have used

Session.Add().

Session.Add("d adapter", sqlDataAdapter1 );
Session.Add("d set", ds);

On the other page I have used a cast to get at the

Session objects that I
supposedly stored on the other page.

SqlDataAdapt er da2 =
(System.Data.S qlClient.SqlDat aAdapter)Sessio n

["dadapter"]);

Dataset ds2 = (System.Data.Da taSet)Session["dset"]);

My code on the page where I want to use the data from the

database(The other
page has the ADO in the component tray) says

Session("dadap ter")=null
Session("dset" )=null

I looked through the MSDN to see if I could get some

error messages out of
the session object, but no go. As far as the ASP.NET I

get the error "object
reference not set to an instance of an object." What

could be wrong?
--
Spencer
.

Nov 19 '05 #7
Hi Spencer,

Apparently in your case, when you add the adapter to
session it is not initialized yet. Since it works
properly, it means you add it to session too early.

In terms of wizard, it is very easy for beginners.
However, if you completely rely on it without
understanding its underlying principles, in a little bit
complicated case you will get lost.

HTH

Elton Wang
-----Original Message-----
Thanks for the help Elton,

I used the sqldataadapterw izard to generate the statements that were neededfor the ado. I know it's a shortcut, but the wizard said all the statementswere generated correctly. It left a protected
system.data.sq lclient.sqldata adapter sqldataadapter1 statement in the wizardgenerated code. I just filled the dataset with it, I didn't bother with new.It appears to be working correctly. I also used it to do an update.
So from what the wizard generated I just added it to the session. Do youthink I should try a new sqldatadapter before the session.add? I am not surehow to create a connection string and the sql statements. As I said, I thinkthe wizard did everything for me. Thanks

Spencer
"Elton Wang" wrote:
Hi Spencer,

Before you use SessionState to hold an object, you should initialize it. Otherwise you only hold a null value in
SessionState. For example, you should do it like following:
SqlDataAdapter sqlDataAdapter1 = New SqlDataAdapter
(sqlQuery, connction);
DataSet ds = new DataSet();
sqlDataAdapter1 .Fill(ds);
Session.Add("da dapter", sqlDataAdapter1 );
Session.Add("ds et", ds);

HTH

Elton Wang
el********@hotm ial.com
>-----Original Message-----
>Hello!,
>
>I have a using system.web.sess ionstate directive one
the top of each of two
>web pages. On the first page I have the dataadapter,

dataconnection, and
>dataset (also in the component tray). I have used

Session.Add().
>
>Session.Add("d adapter", sqlDataAdapter1 );
>Session.Add("d set", ds);
>
>On the other page I have used a cast to get at the

Session objects that I
>supposedly stored on the other page.
>
>SqlDataAdapt er da2 =
>(System.Data.S qlClient.SqlDat aAdapter)Sessio n

["dadapter"]);
>
>Dataset ds2 = (System.Data.Da taSet)Session["dset"]);
>
>My code on the page where I want to use the data from
the database(The other
>page has the ADO in the component tray) says
>
>Session("dadap ter")=null
>Session("dset" )=null
>
>I looked through the MSDN to see if I could get some

error messages out of
>the session object, but no go. As far as the ASP.NET I

get the error "object
>reference not set to an instance of an object." What

could be wrong?
>--
>Spencer
>.
>

.

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2447
by: Abhilash.k.m | last post by:
This is regarding the session management using Out of proc session management(SQL SERVER). Among the samples below which one is better to set the session? 1. There are 20 session variables and all of them are being stored into session and accessed from session and individual session object. Example: Session = "XYZ", Session=100, Session="NAME", etc.
4
2801
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created on the page. So I need multiple forms on a asp.net page(doesn't everyone). I purchased the...
6
2402
by: Shashi | last post by:
I have developed ASP.Net application using .Net 1.1 Framework. When the user clicks image file through Java script I am using my search window as below. QueryString = "frmMySearchWebForm.aspx?DOBDate=" + txtDOBDt popUp =window.open(QueryString,null, "height=50,width=80,status=no,left =0,top =0,toolbar=no,menubar=no,location=no,scrollbars =yes"); When the user picks a certain customer in the frmMySearchWebForm I am
1
6414
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
15
2410
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
7
3964
by: aroraamit81 | last post by:
Well Guys, Here is a very strange trouble. When more than one users request tto same page at the same time then our session gets conflicted. Moreover I printed my SessionID, strangely but true I got the exact same SessionID as of other users's. Well I guess nothing wrong with my code, do I need to set any property in Web.Config file??
0
2558
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation link (1,2,3 so on). The code can be found in SubscriptionCart.aspx.cs. Default.aspx ------------
8
6072
by: inpuarg | last post by:
I 'm developing a c# (.net 2.0) windows forms application and in this application i want to connect to a java servlet page (HTTPS) (which is servlet 2.4 and which may be using Web Based SSO Sun Java System Access Manager but i 'm not sure), handle session management, get token, send data using post and get methods etc. I listened http traffic using Fiddler and sending the same messages from my application but browser based navigation is...
8
2900
by: adarshyam | last post by:
hi.. I am new to vb.net i am doing a program using dynamic textboxes which involves two pages .. where values of textboxes in one page must be transfered to to other sex of textboxes in another page, . please help me .. I tried using session variables but its not working.. this s my code.. PAGE 1 Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click nval2 = TextBox2.Text If...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.