Ciao a tutti,
ho necessità di recuperare l'ultimo id inserito in una tabella.
Ma non l'ulimo ultimo in ordine di tempo, l'ultimo che ho inserito io perchè potrebbero esserci più utenti!
devo fare un'insert in una tabella, recuperare l'id (autoincrementato) di questa fare la insert di dell'id in questione in un'altra tabella.
L'ho chiesto sul fornum ASP perchè pensavo fosse la sessa cosa che in asp net ma forse non proprio o almeno io non ne sono capace...(http://forum.html.it/forum/showthrea...hreadid=591441 )
ho provato a fare così:
'RECUPER L'ULTIMO ID
Dim ConnLastID As SqlConnection
Dim CommLastID As SqlCommand
Dim DRLastID As SqlDataReader
Dim strSQLID as String = "SELECT @@IDENTITY as UltimoID FROM EC_TESTEWEB"
ConnLastID = New SqlConnection(ConfigurationSettings.AppSettings("D BStrConn"))
CommLastID = New SqlCommand(strSQLID, ConnLastID)
CommLastID.CommandType = CommandType.Text
If ConnLastID.State <> ConnectionState.Open Then
ConnLastID.Open()
End If
DRLastID = CommLastID.ExecuteReader
DRLastID.Read()
Dim UltID as String = DRLastID("UltimoID")
me.lbl_conferma.Text = UltID
DRLastID.Close()
ConnLastID.Close()
ma non funziona ( DRLastID("UltimoID") risualta nullo ) e non ho capito nemmeno se è possibile fare una cosa del genere o se hofatto solo un gran casino......![]()
![]()
aiutatemi please!!!!![]()
![]()
![]()