Session DataAdapter / DataSet

  • Thread starter Thread starter Kali
  • Start date Start date
K

Kali

I have an asp.net page that works great in VB.NET, however, I can't seem to
get it to work in C#.

The VB.NET code is...

session("da") = New SqlDataAdapter(strSQL, cn)
session("ds") = New DataSet
session("da").Fill(session("ds"), "titles")
session("dtSource") = session("ds").Tables("titles")

I'm trying the following C# code but it wont compile...

Session["da"] = new SqlDataAdapter(strSQL, cn);
Session["ds"] = new DataSet();
Session["da"].Fill(Session["ds"], "titles");
Session["dtSource"] = Session["ds"].Tables("titles");

..Fill and .Tables causes the error.

I've tried...

(SqlDataAdapter)Session["da"].Fill(Session["ds"], "titles");
(DataSet)Session["dtSource"] = Session["ds"].Tables("titles");

but still wont compile. Any thoughts on how I can correct this issue? I do
require these in session... trying to port an old VB.NET app.

Thanks in advance.

Kal
 
Kali said:
I have an asp.net page that works great in VB.NET, however, I can't seem
to get it to work in C#.

The VB.NET code is...

session("da") = New SqlDataAdapter(strSQL, cn)
session("ds") = New DataSet
session("da").Fill(session("ds"), "titles")
session("dtSource") = session("ds").Tables("titles")

I'm trying the following C# code but it wont compile...

Session["da"] = new SqlDataAdapter(strSQL, cn);
Session["ds"] = new DataSet();
Session["da"].Fill(Session["ds"], "titles");
Session["dtSource"] = Session["ds"].Tables("titles");

.Fill and .Tables causes the error.

I've tried...

(SqlDataAdapter)Session["da"].Fill(Session["ds"], "titles");
(DataSet)Session["dtSource"] = Session["ds"].Tables("titles");

but still wont compile. Any thoughts on how I can correct this issue?
I do require these in session... trying to port an old VB.NET app.

Try:

((SqlDataAdapter)Session["da"]).Fill((DataSet)Session["ds"], "titles");
Session["dtSource"] = ((DataSet)Session["ds"]).Tables["titles"];

Arne
 
Kali said:
I have an asp.net page that works great in VB.NET, however, I can't seem
to get it to work in C#.

The VB.NET code is...

session("da") = New SqlDataAdapter(strSQL, cn)
session("ds") = New DataSet
session("da").Fill(session("ds"), "titles")
session("dtSource") = session("ds").Tables("titles")

I'm trying the following C# code but it wont compile...

Session["da"] = new SqlDataAdapter(strSQL, cn);
Session["ds"] = new DataSet();
Session["da"].Fill(Session["ds"], "titles");
Session["dtSource"] = Session["ds"].Tables("titles");

.Fill and .Tables causes the error.
For the love of all that's holy, do not use the session state for
everything! It's incredibly wasteful. I'm sure you thinkg it "works great",
but let a few hundred users go to town on it and you'll quickly reverse your
opinion.
I've tried...

(SqlDataAdapter)Session["da"].Fill(Session["ds"], "titles");
(DataSet)Session["dtSource"] = Session["ds"].Tables("titles");

but still wont compile. Any thoughts on how I can correct this issue?
I do require these in session... trying to port an old VB.NET app.
Oh well, if you *require* these in the session... Rewrite it anyway! Sheesh.

But OK, assuming you really can't:

SqlDataAdapter da = (SqlDataAdapter) Session["da"];
DataSet ds = (DataSet) Session["ds"];
da.Fill(ds, "titles");
Session["dtSource"] = ds.Tables("titles");

In other words, every time you take something *from* the Session, you have
to cast (storing it in a local variable is optional, but recommended for
readability). When writing a new value to the Session, this is not required.

Really, though, don't do this. If your site is working as VB.NET, then leave
it be. There is no point to "rewriting" it in C# if you're not actually
going to rewrite anything! There are tools that can do automatic conversion
from VB.NET to C#; this is not that hard to do.
 
Kali said:
I have an asp.net page that works great in VB.NET, however, I can't seem to
get it to work in C#.

The VB.NET code is...

session("da") = New SqlDataAdapter(strSQL, cn)
session("ds") = New DataSet
session("da").Fill(session("ds"), "titles")
session("dtSource") = session("ds").Tables("titles")

I'm trying the following C# code but it wont compile...

Session["da"] = new SqlDataAdapter(strSQL, cn);
Session["ds"] = new DataSet();
Session["da"].Fill(Session["ds"], "titles");
Session["dtSource"] = Session["ds"].Tables("titles");

.Fill and .Tables causes the error.

I've tried...

(SqlDataAdapter)Session["da"].Fill(Session["ds"], "titles");
(DataSet)Session["dtSource"] = Session["ds"].Tables("titles");

but still wont compile. Any thoughts on how I can correct this issue? I
do require these in session... trying to port an old VB.NET app.

Thanks in advance.

Kal

Why do you "require" that DataAdapter and the DataSet objects to be stored
in Session? What possible benefit could there be for that?

I can see, possibly, needing the table data stored in Session, but not the
objects that get you to the data. Wouldn't this work?

SqlDataAdapter da = new SqlDataAdapter(strSQL, cn);
DataSet ds = new DataSet();
da.Fill(ds, "titles");
Session["dtSource"] = ds.Tables("titles");

-Scott
 
Back
Top