how to get a column value of the last row in dataset

A

alan

Hi all,

I need to retrive a column value (Id) of a row with the max Id from a
dataset .
It could be done like that:

Ds.Tables(0).Rows(lastrow)("columnname")

but how to get the lastrow index?

any help wold be apreciated.
Marek
 
M

Miha Markic [MVP C#]

Hi Alan,

First, find the id of last row by using DataTable.Compute("MAX(Id")) and
then find that row using DataRowCollection.Find method (something like
table.Rows.Find(id))
Or use a DataView, sort it by id (or any other field) and check the last
row.
 
A

alan

U¿ytkownik "Miha Markic said:
Hi Alan,

First, find the id of last row by using DataTable.Compute("MAX(Id")) and
then find that row using DataRowCollection.Find method (something like
table.Rows.Find(id))
Or use a DataView, sort it by id (or any other field) and check the last
row.

Thank you, it helped me a lot :)
 
W

William \(Bill\) Vaughn

Ah... won't
Ds.Tables(0).Rows(Ds.Tables(0).Rows.Count-1)("columnname")
do it?


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top