I assume you're talking about a System.Data.DataTable ..?
If the last row always has the highest ID then simply get the last row of the table:
DataRow lastRow = yourDataTable.AsEnumerable().Last();
int id = lastRow.Field<int>("ID");
string fileName = lastRow.Field<string>("FILENAME");
string path = lastRow.Field<string>("PATH");
If the last row is not neccessarily the one with the highest ID and you have not defined the ID-column as primary key, then:
int highestID = yourDataTable.AsEnumberable()
.Select(row => row.Field<int>("ID"))
.Max();
DataRow rowWithHighestID = yourDataTable.AsEnumberable()
.Single(row => row.Field<int>("ID") == highestID);
If you do have defined the ID-column as primary key, then:
int highestID = yourDataTable.AsEnumberable()
.Select(row => row.Field<int>("ID"))
.Max();
DataRow rowWithHighestID = yourDataTable.Rows.Find(highestID);
Edit:
The above "middle" solution would be sub-optimal in case your DataTable can contain a lot of rows because it iterates twice over the row collection. This would be better, albeit a bit "uglier":
int highestID = -1;
int indexOfHighestID = -1;
for (int i=0; i<yourDataTable.Rows.Count; i++)
{
int id = row.Field<int>("ID");
if (id > highestID)
{
highestID = id;
indexOfHighestID = i;
}
}
if (indexOfHighestID > 0)
{
DataRow rowWithHighestID = yourDataTable.Rows[indexOfHighestID];
}
Another Edit:
If you need to do that regularly in your application, the best way would be to define a primary key on the ID-column and somewhere keep the highest/last ID you inserted around so that you don't have to find out which one it was. Then it would be simply this:
DataRow rowWithHighestID = yourDataTable.Rows.Find(highestID);