views:

133

answers:

3

In Microsoft Access, there is this DLast function that returns the application key of the last value from a specified set of records. I wonder what is the equivalent of DLast in .Net that enables me to retrieve the primary key of my last insert?

I am using Access over OLEDBConnection

+1  A: 

How come you compare Access and .NET? If you want to express the same in SQL, for thos:

DLast("UnitPrice", "Order Details", "OrderID = 10248")

it will be something like

select top 1 UnitPrice 
    from OrderDetails 
    where OrderID = 10248 
    order by UnitPrice desc
Anton Gogolev
A: 

I think it depends on your Database system, not your development framework (.NET for example).

For SQL Server, take a look at the @@Identity system function.

Cerebrus
+1  A: 

Which database are you using? Is it Access over an OLEDB connection? In that case you can run the DLast function in a query like this:

SELECT DLast("COLUMNNAME","TABLENAME","WHERE CLAUSE");
Rune Grimstad