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