Session DataAdapter / DataSet

Discussion in 'ASP .Net' started by Kali, Oct 25, 2009.

  1. Kali

    Kali Guest

    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, Oct 25, 2009
    #1
    1. Advertising

  2. Kali

    Arne Vajhøj Guest

    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
     
    Arne Vajhøj, Oct 25, 2009
    #2
    1. Advertising

  3. 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.
     
    Jeroen Mostert, Oct 25, 2009
    #3
  4. Kali

    Scott M. Guest

    "Kali" <> wrote in message
    news:%23A%...
    >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
     
    Scott M., Oct 26, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Galen Harris

    dataadapter.update -- dataset from session

    Galen Harris, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    547
    Jacob Yang [MSFT]
    Oct 24, 2003
  2. Galen Harris
    Replies:
    1
    Views:
    473
    Patrik Löwendahl
    Oct 24, 2003
  3. Amadelle
    Replies:
    1
    Views:
    375
    John Saunders
    Jun 5, 2004
  4. =?Utf-8?B?Qm9vbmFhcA==?=

    typed dataset - dataAdapter - parameter question

    =?Utf-8?B?Qm9vbmFhcA==?=, Jun 23, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    605
    =?Utf-8?B?Qm9vbmFhcA==?=
    Jun 23, 2005
  5. Rui Dias

    Problems with dataset and dataadapter

    Rui Dias, Aug 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    504
    Rui Dias
    Aug 19, 2005
Loading...

Share This Page