Solved

Last record in datarow

Posted on 2010-09-03
4
634 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now