Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session DataAdapter / DataSet

Reply
Thread Tools

Session DataAdapter / DataSet

 
 
Kali
Guest
Posts: n/a
 
      10-25-2009
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


 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-25-2009
Kali wrote:
> 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
 
Reply With Quote
 
 
 
 
Jeroen Mostert
Guest
Posts: n/a
 
      10-25-2009
Kali wrote:
> 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.

--
J.
 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      10-26-2009

"Kali" <(E-Mail Removed)> wrote in message
news:%23A%(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typed dataset - dataAdapter - parameter question =?Utf-8?B?Qm9vbmFhcA==?= ASP .Net 0 06-23-2005 11:57 AM
dataset and dataadapter persistance between page loads Amadelle ASP .Net 1 06-05-2004 02:47 AM
Could not display a column in Access 2000 nwind.mdb in a listbox using ole DataAdapter, Connection and dataset controls yma ASP .Net 1 12-16-2003 06:20 PM
dataadapter.update -- dataset from session Galen Harris ASP .Net 1 10-24-2003 06:02 AM
DataAdapter.update() and a DataSet in session Galen Harris ASP .Net 1 10-23-2003 11:50 PM



Advertisments