Using Session.add() with ado

G

Guest

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?
 
T

Tampa.NET Koder

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.
 
G

Guest

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 said:
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 said:
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?
 
T

Tampa.NET Koder

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 said:
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 said:
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.


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?
 
G

Guest

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 said:
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 said:
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 said:
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.


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?
 
E

Elton Wang

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
(e-mail address removed)
 
G

Guest

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 said:
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
(e-mail address removed)


-----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?
 
E

Elton Wang

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 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 said:
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
(e-mail address removed)


-----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?
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top