Originariamente inviato da Marconline
...devo recuperare l'ultimo id da una tabella.. Come si fa?
Tiro a indovinare che stai usando sql server. Se e' cosi, oltre al consiglio di usare il suo dataprovider specifico system.data.sqlclient e non oledb, ti suggerisco di utilizzare le funzioni di sistema pronte da usare per questo scopo e cioe' es.
codice:
SELECT IDENT_CURRENT('nometabella')
ma volendo anche @@IDENTITY e/o SCOPE_IDENTITY .
Copio e incollo dal book online di sqlserver...
@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table.

@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.

IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.