Dataset - Get Values

Discussion in 'ASP .Net' started by shapper, Sep 25, 2007.

  1. shapper

    shapper Guest

    Hello,
    I have an SQL Stored Procedure that uses Inner Join to return the
    records of various related tables:
    SELECT * FROM dbo.by27_Blogger_Posts p
    LEFT JOIN (
    SELECT *
    FROM dbo.by27_Blogger_Comments c
    LEFT JOIN dbo.by27_Membership_Users u
    ON c.AuthorId = u.UserId) AS cu
    ON p.PostId = cu.PostId
    ....
    WHEREp.PostId = @PostId
    ORDER BY p.PostUpdatedDate

    Now I get a dataset with all this data.
    How can I, for example, loop through each PostId? And for each PostId
    loop through each CommentId associated to it? And of course access the
    columns?

    The SQL code section I post applies to the 2 tables:
    [Posts] > PostId, Title, ...
    [Comments] > CommentId, PostId, Body, ...

    Thanks,
    Miguel
     
    shapper, Sep 25, 2007
    #1
    1. Advertising

  2. Hi Miguel,

    Maybe check out Scott Guthrie's ASP.NET data access tutorials, the
    sections about Typed DataSets and TableAdapters might be useful to
    you.

    http://www.asp.net/learn/data-access/#advanced

    Chris

    On Sep 25, 11:29 am, shapper <> wrote:
    > Hello,
    > I have an SQL Stored Procedure that uses Inner Join to return the
    > records of various related tables:
    > SELECT * FROM dbo.by27_Blogger_Posts p
    > LEFT JOIN (
    > SELECT *
    > FROM dbo.by27_Blogger_Comments c
    > LEFT JOIN dbo.by27_Membership_Users u
    > ON c.AuthorId = u.UserId) AS cu
    > ON p.PostId = cu.PostId
    > ...
    > WHEREp.PostId = @PostId
    > ORDER BY p.PostUpdatedDate
    >
    > Now I get a dataset with all this data.
    > How can I, for example, loop through each PostId? And for each PostId
    > loop through each CommentId associated to it? And of course access the
    > columns?
    >
    > The SQL code section I post applies to the 2 tables:
    > [Posts] > PostId, Title, ...
    > [Comments] > CommentId, PostId, Body, ...
    >
    > Thanks,
    > Miguel
     
    Chris Fulstow, Sep 25, 2007
    #2
    1. Advertising

  3. The SQL Statement you show will return a single resultset. So the DataSet you
    get back from this will have a single DataTable with all the columns.
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "shapper" wrote:

    > Hello,
    > I have an SQL Stored Procedure that uses Inner Join to return the
    > records of various related tables:
    > SELECT * FROM dbo.by27_Blogger_Posts p
    > LEFT JOIN (
    > SELECT *
    > FROM dbo.by27_Blogger_Comments c
    > LEFT JOIN dbo.by27_Membership_Users u
    > ON c.AuthorId = u.UserId) AS cu
    > ON p.PostId = cu.PostId
    > ....
    > WHEREp.PostId = @PostId
    > ORDER BY p.PostUpdatedDate
    >
    > Now I get a dataset with all this data.
    > How can I, for example, loop through each PostId? And for each PostId
    > loop through each CommentId associated to it? And of course access the
    > columns?
    >
    > The SQL code section I post applies to the 2 tables:
    > [Posts] > PostId, Title, ...
    > [Comments] > CommentId, PostId, Body, ...
    >
    > Thanks,
    > Miguel
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Sep 25, 2007
    #3
  4. shapper

    shapper Guest

    On Sep 25, 12:48 pm, Peter Bromberg [C# MVP]
    <> wrote:
    > The SQL Statement you show will return a single resultset. So the DataSet you
    > get back from this will have a single DataTable with all the columns.
    > -- Peter
    > Recursion: see Recursion
    > site: http://www.eggheadcafe.com
    > unBlog: http://petesbloggerama.blogspot.com
    > BlogMetaFinder: http://www.blogmetafinder.com
    >
    > "shapper" wrote:
    > > Hello,
    > > I have an SQL Stored Procedure that uses Inner Join to return the
    > > records of various related tables:
    > > SELECT * FROM dbo.by27_Blogger_Posts p
    > > LEFT JOIN (
    > > SELECT *
    > > FROM dbo.by27_Blogger_Comments c
    > > LEFT JOIN dbo.by27_Membership_Users u
    > > ON c.AuthorId = u.UserId) AS cu
    > > ON p.PostId = cu.PostId
    > > ....
    > > WHEREp.PostId = @PostId
    > > ORDER BY p.PostUpdatedDate

    >
    > > Now I get a dataset with all this data.
    > > How can I, for example, loop through each PostId? And for each PostId
    > > loop through each CommentId associated to it? And of course access the
    > > columns?

    >
    > > The SQL code section I post applies to the 2 tables:
    > > [Posts] > PostId, Title, ...
    > > [Comments] > CommentId, PostId, Body, ...

    >
    > > Thanks,
    > > Miguel


    Peter,

    I know but the question is:
    Is it possible to create the loop I mentioned or should I use various
    SELECTs to return various tables?

    Thanks,
    Miguel
     
    shapper, Sep 25, 2007
    #4
  5. shapper

    sloan Guest

    I already responded to this yesterday.

    My suggestion was to have 2 resultsets (2 select statements) coming back,
    and process those.

    I gave a link to a complete working example.

    .....

    Do you have a weak (untyped) or strong (typed) dataset you're dealing with?

    ...

    Check my blog (again) and find the 1.1 version of the example I gave you
    "Custom Objects in 1.1" or something like that.
    I have extra dataset code there.





    "shapper" <> wrote in message
    news:...
    > On Sep 25, 12:48 pm, Peter Bromberg [C# MVP]
    > <> wrote:
    >> The SQL Statement you show will return a single resultset. So the DataSet
    >> you
    >> get back from this will have a single DataTable with all the columns.
    >> -- Peter
    >> Recursion: see Recursion
    >> site: http://www.eggheadcafe.com
    >> unBlog: http://petesbloggerama.blogspot.com
    >> BlogMetaFinder: http://www.blogmetafinder.com
    >>
    >> "shapper" wrote:
    >> > Hello,
    >> > I have an SQL Stored Procedure that uses Inner Join to return the
    >> > records of various related tables:
    >> > SELECT * FROM dbo.by27_Blogger_Posts p
    >> > LEFT JOIN (
    >> > SELECT *
    >> > FROM dbo.by27_Blogger_Comments c
    >> > LEFT JOIN dbo.by27_Membership_Users u
    >> > ON c.AuthorId = u.UserId) AS cu
    >> > ON p.PostId = cu.PostId
    >> > ....
    >> > WHEREp.PostId = @PostId
    >> > ORDER BY p.PostUpdatedDate

    >>
    >> > Now I get a dataset with all this data.
    >> > How can I, for example, loop through each PostId? And for each PostId
    >> > loop through each CommentId associated to it? And of course access the
    >> > columns?

    >>
    >> > The SQL code section I post applies to the 2 tables:
    >> > [Posts] > PostId, Title, ...
    >> > [Comments] > CommentId, PostId, Body, ...

    >>
    >> > Thanks,
    >> > Miguel

    >
    > Peter,
    >
    > I know but the question is:
    > Is it possible to create the loop I mentioned or should I use various
    > SELECTs to return various tables?
    >
    > Thanks,
    > Miguel
    >
     
    sloan, Sep 25, 2007
    #5
    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. Nedu N
    Replies:
    1
    Views:
    1,809
    Chris Taylor
    Oct 31, 2003
  2. JimO

    DataSet and dataSet

    JimO, Mar 1, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    530
    Mary Chipman [MSFT]
    Mar 8, 2006
  3. vighnesh
    Replies:
    3
    Views:
    1,029
    Paul Clement
    Aug 4, 2005
  4. vighnesh
    Replies:
    3
    Views:
    185
    Paul Clement
    Aug 4, 2005
  5. Replies:
    0
    Views:
    114
Loading...

Share This Page