Retrieving id field ?

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

Hi, how can I retrieve the id from identity field generated by sql server
after a insert into instruction? Is that possible? Using .net 2.0 C# VS 2005
and
"ExecuteNonQuery"

Thanks in advance!
 
Searching on Google I found this example on classic ASP:

strSQL = "SET NOCOUNT ON INSERT INTO tblName(TextField, NumberField)
VALUES('ABC', 123) SELECT @@IDENTITY AS NewID SET NOCOUNT OFF"

strConnection = "Provider=SQLOLEDB.1;Password=YourPassword;Persist Security
Info_
=True;User ID=YourUserID; Initial Catalog=YourDB;_
Data Source=YOUR_REMOTE_SERVER_NAME"

Set commInsert = Server.CreateObject("ADODB.Connection")
commInsert.Open strConnection
Set rsNewID = commInsert.Execute(strSQL)
intNewID = rsNewID("NewID")
commInsert.Close()

rsNewID("NewID") can be returned using the "ExecuteNonQuery" on asp.net 2.0
?
 
Back
Top