• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

Last record in datarow

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
Simon Cripps
Asked:
Simon Cripps
  • 2
1 Solution
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
try this
datatable.rows(datatable.rows.count-1).item("name").tostring
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
same result:
Dim row As DataRow = table.Rows(table.Rows.Count - 1) 'Where Table Your Table Name
        Console.WriteLine(row("ColumnName"))
0
 
ZhaolaiCommented:
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
 
Simon CrippsOwnerAuthor Commented:
All good suggestions, the last one worked best for me.
Cheers
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now