Solved

Last record in datarow

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

828 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