Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP5's Crazy Cursor
Message
From
23/01/2003 19:16:34
 
 
To
23/01/2003 17:57:02
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00744906
Message ID:
00744930
Views:
39
>**** QUESTION!!!! **************************
>* I have .DBC VFP5's DB. And a table with name of "USUARIOS"
>* USUARIOS basicly has the field USRID C(20): Candidate Key
>* ID int: Primary Key, Nom C(25)
>* In a Form's Private DataSession the table is included.
>
>* In the first step the form's "modifica" method modified
>* USRID: "UNO" to "UNOttt" .. and it works correct.
>
>* But later in second step i would try to modify with "modifica" method the
>* data USRID: "UNOttt" to "UNO" i found the message in the bellow code
>* MESSAGEBOX("ID Exists ... Choose another ...") .. you can finde this
>* in the fallowing source code where i marked with *OJO*
>* Thus i thought that the Cursor in Private DataSession had problem or is crazy.
>* What a crezy cursor ....
>* The similar problem occured with INSERT ..
>
>* PLEASE HELP ME ...
>
>********************************************
>
>
>SET EXACTO ON .. in Form's init event
>
>
>* PROPIEDAD DE FORMULARIO
>* buffermode = 2 - OPTIMISTIC
>* DataSession = 2 - PRIVATE
>* Tablas en Datasession : USUARIOS,
>* KEYS -- this is the table to manage and get the next PK for the table
>* of which the name is passed .. to INSERT a new record.
>* This is because VFP5's Db dose not support autoincrement field for PK.
>
>********************************************
>
>
>LOCAL lcUID,lcNom , lcSql, lnCT, lnID, llError
>
>SUSPEND
>
>
>lcUID = ALLTRIM(THISFORM.txtUsrId.Value)
>lcNom = ALLTRIM(THISFORM.txtNombre.Value)
>lnID = THISFORM.lstUsuarios.ItemData(THISFORM.lstUsuarios.ListIndex)
>
>
>lcSql = "SELECT USRID FROM USUARIOS WHERE USRID == " + "'" + lcUID + "'" + " INTO CURSOR TEMP"
>&lcSql
>SELECT TEMP
>lnCT=RECCOUNT('TEMP')
>USE
>
>*OJO*
>IF lnCT > 0
>MESSAGEBOX("ID Exists ... Choose another ...")
>RETURN .F.
>ENDIF
>
>
>lcSql = "UPDATE USUARIOS SET USRID = " + "'" + lcUID + "'" ;
>+ ", NOM = " + "'" + lcNom + "'" ;
>+ " WHERE ID = " + STR(lnID )
>
>
>BEGIN TRANSACTION
>
>ON ERROR llError = .T.
>&lcSql
>IF llError
>ROLLBACK
>=MESSAGEBOX(MESSAGE())
>ELSE
>END TRANSACTION
>
>WITH THISFORM
>.lstUsuarios.List(.lstUsuarios.ListIndex) = lcUID + SPACE(4) + lcNom
>.txtUSRID.Value = ""
>.txtNombre.Value = ""
>ENDWITH
>
>ENDIF
>
>ON ERROR
>
>
>
>verdin40@yahoo.co.kr
>verdin41@hotmail.com


Change your BEGIN ... END TRANSACTION with this
BEGIN TRANSACTION
   ON ERROR llError = .T.
   &lcSql
   IF llError
      RollBack
      = TableRevert(.T.)
      = MESSAGEBOX(MESSAGE())
   else
      = TableUpdate(.T.)
      WITH THISFORM
         .lstUsuarios.List(.lstUsuarios.ListIndex) = lcUID + SPACE(4) + lcNom
         .txtUSRID.Value = ""
         .txtNombre.Value = ""
      ENDWITH
   endif
END TRANSACTION
Herman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform