Learning value of identity field on SQL Server 7 after ADO-based insert

Learning value of identity field on SQL Server 7 after ADO-based insert

Post by gamma.. » Wed, 22 Mar 2000 04:00:00



Hi Everyone,

I'm working on a program that needs to add a record to a SQL Svr 7 table
that contains an identity column. I'm using the rs.AddNew ... rs.Update
syntax on an ADO recordset. How can I learn the identity value of the
new record right after the Update statement fires and the record is
inserted into the SQL table?

Thanks very much for any help you can offer!

- Jim

 
 
 

Learning value of identity field on SQL Server 7 after ADO-based insert

Post by Dennis Che » Thu, 23 Mar 2000 04:00:00



rs(0)--------->Value of Identity
rs is ado recordset object
cn is ado connection object

> Hi Everyone,

> I'm working on a program that needs to add a record to a SQL Svr 7 table
> that contains an identity column. I'm using the rs.AddNew ... rs.Update
> syntax on an ADO recordset. How can I learn the identity value of the
> new record right after the Update statement fires and the record is
> inserted into the SQL table?

> Thanks very much for any help you can offer!

> - Jim


 
 
 

Learning value of identity field on SQL Server 7 after ADO-based insert

Post by José Pedr » Sat, 25 Mar 2000 04:00:00


What you need to do is after rs.Update, you put the value of the identity
value into a variable.

example

rs.update

variable = rs!(identity value)

rs.close


> Hi Everyone,

> I'm working on a program that needs to add a record to a SQL Svr 7 table
> that contains an identity column. I'm using the rs.AddNew ... rs.Update
> syntax on an ADO recordset. How can I learn the identity value of the
> new record right after the Update statement fires and the record is
> inserted into the SQL table?

> Thanks very much for any help you can offer!

> - Jim