473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Using Session.add() with ado

Hello!,

I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session["dadapter"]);

Dataset ds2 = (System.Data.DataSet)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("dadapter")=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 2542
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**********@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com...
Hello!,

I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session["dadapter"]);

Dataset ds2 = (System.Data.DataSet)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("dadapter")=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**********@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com...
Hello!,

I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session["dadapter"]);

Dataset ds2 = (System.Data.DataSet)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("dadapter")=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**********@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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**********@discussions.microsoft.com> wrote in
message
news:BE**********************************@microsof t.com...
> Hello!,
>
> I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
> Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session["dadapter"]);
>
> Dataset ds2 = (System.Data.DataSet)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("dadapter")=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.sqlclient.sqldataadapter)session["dadapter"]
dataset ds2 = (system.data.dataset)session["dset"]
da2 = new sqldataadapter()
ds2 = new dataset()
da2.fill(ds2)
Web page(aspx) with ado.net in component tray

Session.add("dadapter", sqldataadapter1);
Session.add("dset", 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**********@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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**********@discussions.microsoft.com> wrote in
message
news:BE**********************************@microsof t.com...
> Hello!,
>
> I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
> Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session["dadapter"]);
>
> Dataset ds2 = (System.Data.DataSet)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("dadapter")=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("dadapter", sqlDataAdapter1);
Session.Add("dset", ds);

HTH

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

I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
Session.Add("dset", ds);

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

SqlDataAdapter da2 =
(System.Data.SqlClient.SqlDataAdapter)Session ["dadapter"]);
Dataset ds2 = (System.Data.DataSet)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("dadapter")=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 sqldataadapterwizard 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.sqlclient.sqldataadapter 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("dadapter", sqlDataAdapter1);
Session.Add("dset", ds);

HTH

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

I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session

["dadapter"]);

Dataset ds2 = (System.Data.DataSet)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("dadapter")=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 sqldataadapterwizard 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.sqlclient.sqldataadapter 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("dadapter", sqlDataAdapter1);
Session.Add("dset", ds);

HTH

Elton Wang
el********@hotmial.com
>-----Original Message-----
>Hello!,
>
>I have a using system.web.sessionstate 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("dadapter", sqlDataAdapter1);
>Session.Add("dset", 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.SqlClient.SqlDataAdapter)Session

["dadapter"]);
>
>Dataset ds2 = (System.Data.DataSet)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("dadapter")=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
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...
4
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...
6
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 =...
1
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...
15
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...
7
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...
0
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...
8
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...
8
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,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.