Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to retrieve SQL Identity Column values?
Message
From
02/10/2001 10:35:48
 
 
To
02/10/2001 10:19:08
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00562994
Message ID:
00563015
Views:
24
This message has been marked as the solution to the initial question of the thread.
Hi!
select MyData
llNewRec = (chrtran(getfldstate(-1),"34","")=="")
tableupdate(...) 
if llNewRec
  nHandle = cursorgetprop("ConnectHandle","MyData")
  =SQLEXEC(nHandle, "SELECT @@IDENTITY as nID","MyCursor")
  if used("MyCursor") AND !IsNull(MyCursor.nID)
    replace MyData.nID with MyCursor.nID
    select MyData
    tableupdate(...) && update it again, but make nID field not updatable. This will not generate real 
         &&update to SQL Server, but it is needed just to store nID in the cursor and mark it as it 
         && is not changed. SetFldState() function do nto works in this place.
  endif
  if used("MyCursor")
    use in MyCursor
  endif
endif
HTH.

>I'm using VFP 6 and SQL 2000. Almost all SQL tables have an identity column for the pk. When I add a new record to a view, is there a direct way to retrieve the PK value that was assigned by SQL? I currently do some pretty serious gyrations to pull it off. Must be a quicker way...
>
>TIA
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform