Get data from dataset

S

shapper

Hello,

I have a stored procedures as follows:

SELECT a.ArticleID, a.Title, a.Content, c.CommentId, c.Title,
c.Comment
FROM Articles a
INNER JOIN Comments c ON a.ArticleID = c.CommentID
WHERE a.ArticleDate = @articledate

I get a dataset in my .NET code.

How can I get, from my dataset, given for example its ID, the title
and content of an article and all the titles and comments related with
that article?

Thanks,

Miguel
 
S

shapper


Hi,

A correction for my SQL Procedure:

SELECT a.ArticleID, a.Title, a.Content, c.CommentId, c.Title,
c.Comment
FROM Articles a
INNER JOIN Comments c ON a.ArticleID = c.ArticleID
WHERE a.ArticleDate = @articledate

Mark,

I know how to access a row of article:

Dim row As DataRow
For Each row In dataset.Tables(0).Rows

Article.ArticleId = (dataset("ArticleId")
Article.Title = (dataset("ArticleTitle")
...

Next row

My problem is how to access the comments for a given article in my
dataset.

I want to loop through each article and their comments and fell the
properties of two classes:

Article has the properties:

ArticleID, ArticleTitle, ArticleContent and Generic.List(Of Comment)

Comment has the properties:

CommentID, CommentTitle, CommentComment

I want to feel the class properties with the dataset values.

How can I do this?

Thanks,
Miguel
 
S

sloan

Huh? You gotta piggy back on the row.

Dim row As DataRow
For Each row In dataset.Tables(0).Rows

dim a as Article = new Article
a.ArticleId = Convert.ToInt32 ( row("ArticleID") )
a.Title = convert.ToString( row("Title") )
a.Content = convert.ToString( row("Content"))

' a.Comment.CommentID = 'left for you to do
' a.CommentTitle = 'left for you to do
' a.CommentComment = 'left for you to do


mycollection.Add(a) ' << you don't have this



If you have a strongly typed dataset, you need to probably cast the "row" as
the specific type of row you have
(Like if you have an Employee table in your dataset, you'd cast row as
'EmployeeRow")





If you need a full example of changing data into business objects ,
see

6/5/2006
Custom Objects and Tiered Development II // 2.0
http://sholliday.spaces.live.com/blog/


I use and IDataReader, but its the same concept.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top