Solved

Last record in datarow

Posted on 2010-09-03
4
662 Views
Last Modified: 2012-05-10
Hi is there any way I can identify the last DataRow in a table.
What I would like to do is list some items seperated by a comma apart from the last item.

such as:

For Each grandchildRow As DataRow In childRow.GetChildRows("GrandChildren")

If not last row
CategoryLabel.Text = (grandchildRow("DCategory").ToString()) + ", "
else if last row
CategoryLabel.Text = (grandchildRow("DCategory").ToString())
Next

But what do I put to identify the last row?

Cheers
0
Comment
Question by:Simon Cripps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33596725
try this
datatable.rows(datatable.rows.count-1).item("name").tostring
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33596785
same result:
Dim row As DataRow = table.Rows(table.Rows.Count - 1) 'Where Table Your Table Name
        Console.WriteLine(row("ColumnName"))
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 33596954
You can use count to compare, like this:

Dim iCount as Integer
Dim iRows as Integer = childRow.GetChildRows.Count
For Each grandchildRow As DataRow In childRow.GetChildRows("GrandChildren")
iCount += 1
If iCount < iRows then
CategoryLabel.Text = (grandchildRow("DCategory").ToString()) + ", "
else
CategoryLabel.Text = (grandchildRow("DCategory").ToString())
 End If
Next

0
 

Author Closing Comment

by:Simon Cripps
ID: 33600480
All good suggestions, the last one worked best for me.
Cheers
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question