Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primary Key
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00532997
Message ID:
00534907
Views:
11
Leroy,

In a busy, multi-user system, this code will fail. There is nothing to stop two people from generating the same key at the same time. There is an article on my website that discusses PKs and has code to do it for you.


>>
>I have problem with primary key, when I delete record and enter new record with same value in primary field error come value already exist. If any body has a solution, please reply
>
>Hi Javed!!!
>I had that very same problem last week.
>If you want to keep the deleted records for the history or something try this method.
>
>
>FUNCTION GET_PRIMARY_KEY
>LPARAMETER lcTable,lcFieldName,lcIndexOnExp
>LOCAL lnLastNum,lnNewNum
>
>SELECT &lcTable
>SKIP -1
>lnLastNum = &lcFieldName
>SKIP
>IF !USED('DATA\IDS') 	  && my table of ids
>	USE ('DATA\IDS') IN 0	
>ENDIF	
>SELECT IDS
>SET ORDER TO ID
>IF !SEEK(lnLastNum)   && if I don't find it in my table of ids
>	append blank
>	replace id with lnLastNum
>	replace iddescp with left(spellamt(lnLastNum),AT('And',spellamt(lnLastNum))-1)
>ENDIF
>lnNewNum = IDS.ID + 1
>SELECT IDS
>USE
>SELECT &lcTable   && the table i want the key in
>SET DELETED OFF
><b>DO WHILE SEEK(lnNewNum)  && check to see if that number is in there
>	lnNewNum = lnNewNum + 1
>ENDDO  && when it is not, pop out</b>
>SET DELETED ON
>RETURN lnNewNum
>ENDFUNC
>
>
>As much as I don't like the Do WHILE, This was the only way I could get it to work in my table. The Do While Statement might be what you need.
>
>HTH
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform