469,963 Members | 2,044 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

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 2423
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Abhilash.k.m | last post: by
4 posts views Thread by Kevin Phifer | last post: by
1 post views Thread by ratnakarp | last post: by
7 posts views Thread by aroraamit81 | last post: by
reply views Thread by Eugene Anthony | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.