[thelist] Using @@Identity

Casey aspnet at thecrookstons.com
Tue Aug 23 19:49:43 CDT 2005


Joshua said:

> Add a trigger to the table on insert:
>
> CREATE TRIGGER mytable_insert ON dbo.mytable
> FOR INSERT
> AS SELECT @@identity AS id
>
> Then, whenever you insert a record you'll automatically get back a
recordset
> containing the inserted identity.
>
> In ASP:
> Set oRS = oConn.Execute("INSERT INTO mytable...")
> Response.Write "Inserted ID: " & oRS("id")

Casey replied:

Yes, I was thinking along the same lines.  Of course, I'm using ASP.NET
rather then classic ASP.  After inserting the new record, I tried this:

Dim doc_id as integer = cmdInsert("Identity")

But got this error:

 BC30367: Class 'System.Data.SqlClient.SqlCommand' cannot be indexed because
it has no default property.


- Becoming rather frustrated.



More information about the thelist mailing list