Groups > dBase > dBase SQL Servers > Re: Value of identity field




Value of identity field

Value of identity field
Fri, 11 Apr 2008 14:54:50 +100
Hi All,
Is there any way to determine the value of an identity field as it is 
being created? E.G.


form.rowset.beginappend()
form.rowset.fields["myfield"].value="BlaBla"
//I would like to know the value of the identity field 
(form.rowset.fields["invoice_no"].value) now so I can populate a child

table.


TIA

Trevor

Post Reply
Re: Value of identity field
Fri, 11 Apr 2008 20:20:45 +020
Trevor wrote 

> Is there any way to determine the value of an identity field as it is 
> being created? E.G.
> 
> 
> form.rowset.beginappend()
> form.rowset.fields["myfield"].value="BlaBla"
> //I would like to know the value of the identity field 
> (form.rowset.fields["invoice_no"].value) now so I can populate a
child 
> table.
--------
From your previous post in this newsgroup I gather you use MS SQL Server.

Check out this article:

http://www.sqlteam.com/article/understanding-identity-columns

I followed the steps described.

First I created the table on MS SQL Server and added some records. 
Then I ran the dBASE program below.

And, to my surprise, it worked!

Roland


// Demo: How to retrieve value of an identity field in MS SQL Server
db = new database("")
db.active := true

q1 = new query()
q1.database = db
q1.sql := [INSERT INTO dbo.Yaks (YakName) values ('Yet another the Yak')]
q1.requestlive = false
q1.active := true

q2 = new query()
q2.database = db
q2.sql := [SELECT SCOPE_IDENTITY() as NewRec]
q2.requestlive = false
q2.active := true

? "NewRec ID:", q2.rowset.fields["NewRec"].value

return
Post Reply
about | contact