Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CA - AutoRefresh
Message
 
À
06/09/2005 17:09:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro Beta
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
00955384
Message ID:
01047946
Vues:
17
Hi Fabio,

SCOPE_IDENTITY() always returns 0 for me... and @@IDENTITY returns the wrong value (T2 table).

If you have time, please just run the code below and then tell me if it happens with you too.

First of all, create tables in SQL Server:
USE tempdb
GO
CREATE TABLE T1 (
   Z_id  int IDENTITY(1,1)PRIMARY KEY,
   Z_name varchar(20) NOT NULL)
CREATE TABLE T2 (
   Y_id  int IDENTITY(100,5)PRIMARY KEY,
   Y_name varchar(20) NULL)
and then, create a trigger that inserts one record in T2 table each time we insert one record in T1 table.
CREATE TRIGGER T1_trig
ON T1
FOR INSERT AS 
   BEGIN
   INSERT T2 VALUES ('')
   END
So, everthing in SQL is ok... Now VFP code:
nAutoRefreshConn=SQLSTRINGCONNECT("DRIVER=SQL Server;SERVER=(local);Trusted_Connection=Yes;database=tempdb")

Local oCA As CursorAdapter

oCA=CREATEOBJECT("CursorAdapter")

oCA.Alias = "CATest"  
oCA.BufferModeOverride= 5 
oCA.DataSource= nAutoRefreshConn  
oCA.DataSourceType="ODBC"  
oCA.SelectCmd="select * from t1"  
oCA.CursorSchema="z_id I, z_name C(10)"    
oCA.UseCursorSchema= .T.
oCA.Tables="t1"
oCA.UpdatableFieldList="z_name"
oCA.UpdateNameList="z_id t1.z_id, z_name t1.z_name"
oCA.CursorFill()

oCA.InsertCmdRefreshFieldList="z_id"
oCA.InsertCmdRefreshCmd="SELECT SCOPE_IDENTITY()"

* oCA.InsertCmdRefreshCmd="SELECT @@IDENTITY" && CursorAdapter returns a wrong number
* oCA.InsertCmdRefreshCmd="SELECT z_id From t1 Where z_id = @@IDENTITY" && CursorAdapter returns an error: The refresh key defined for table is not found
* oCA.InsertCmdRefreshCmd="SELECT z_id From t1 Where z_id = SCOPE_IDENTITY()" && CursorAdapter returns an error: The refresh key defined for table is not found

INSERT INTO CATest (z_name) VALUES ('Rodolfo')
INSERT INTO CATest (z_name) VALUES ('Denise')
INSERT INTO CATest (z_name) VALUES ('Carol')

IF !TABLEUPDATE(.T.)
 	? "TABLEUPDATE is failed!!!"  
   AERROR(aerrs)  
   DISPLAY MEMORY LIKE aerrs  
ELSE
	LIST 
ENDIF
SQLDisconnect(nAutoRefreshConn)
Return .T.
If everthing runs like here, you will see something like that:
Record#    z_id    z_name
1             0    Rodolfo
2             0    Denise
3             0    Carol
Then, if you run this code again, you will get:
Record#    z_id    z_name
1             1    Rodolfo
2             2    Denise
3             3    Carol
4             0    Rodolfo
5             0    Denise
6             0    Carol
Thanks a lot for help me!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Rodolfo Duarte
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform