Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About AutoInc field

Status
Not open for further replies.

zallen

Programmer
Aug 10, 2000
227
CN
when using
TClientDataSet<->TADOQuery+TDataSetProvider<->SQL server 7,how do the client get the IDentity field value in time after inserting a record!

Any help are appreciated! [sig][/sig]
 
There is a command: SELECT @@IDentity
Put this in the same AdoQuery component with the insert command. Call Open instead of ExecSql to retreive the data. It will return the Identity field for the record just added. i.e.
In the AdoQuery.Sql property enter

INSERT INTO TestTable (field1, Field2)
Values('Test1','Test2')
Select @@Identity as AutoIncFieldName

Then in the code call Open or Active := TRUE. This should give you the value of the identity.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top