Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Last record in datarow

Posted on 2010-09-03
4
Medium Priority
?
690 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 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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