Get data from dataset

  • Thread starter Thread starter shapper
  • Start date Start date
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
 

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