Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 174689 - Last Review: February 16, 2005 - Revision: 1.3
HOWTO: Set a Primary Key to Updateable in a View
This article was previously published under Q174689
By default, when creating a view on a table, any field with a primary key
index is not marked as updateable. This article illustrates how you can
mark the primary key as updateable through the View Designer, and
programmatically.
View Designer
To mark the primary key as updateable through the View Designer interface,
use the following steps:
- Open the view in the View Designer.
- Click the Update Criteria tab.
- Click the Update column beside the primary key field.
NOTE: The Update column has a column header that looks like a pencil. If
you do not select the Update column and you attempt to INSERT a new
record, you may receive one of the following errors:
Connectivity error: [Microsoft][ODBC Visual FoxPro Driver
Field <fieldname> does not accept null values.
-or-
Mandatory not null field - missing or null during insert.
Programmatically
To mark the primary key as updateable programmatically, use the following
steps:
- Open the Tastrade database in the VFP\Samples\Tastrade\Data folder in
Visual FoxPro 5.0, or the home(2)+"Tastrade\Data" folder in Visual
FoxPro 6.0.
- Run the following program to create a new SQL view based on the
Customer table.
***********RunFirst.prg***********
CREATE SQL VIEW MYTEST AS SELECT * FROM CUSTOMER
DBSETPROP("MYTEST","VIEW","SENDUPDATES",.T.)
***********End RunFirst.prg*************
- Modify the view in the View Designer and note that the primary key is
not marked for updates.
- Create a program called MarkPrimary and place the following code in it:
************MarkPrimary.prg****************
PARAMETERS ViewName
x=ALIAS()
USE IN 0 &viewname
PrimKeys = CURSORGETPROP('KeyFieldList',viewname)
i=1
remField=PrimKeys
DO WHILE i <> 0
nextcomma=AT(remField,",")
IF nextcomma=0 and len(remfield)=0 THEN
i=0
EXIT
ELSE
IF nextcomma=0 and LEN(remfield)<>0 then
tmpfield=remfield
y= DBSETPROP(ViewName + "." + ;
tmpField,'Field','UPDATABLE',.T.)
i=0
EXIT
ELSE
tmpField=SUBSTR(remField,i,NextComma -1)
remfield=SUBSTR(remfield,nextcomma + 1)
i=nextcomma
y= DBSETPROP(ViewName + "." + ;
tmpField,'Field','UPDATABLE',.T.)
ENDIF
ENDIF
ENDDO
SELECT (viewname)
USE
IF NOT EMPTY(x) THEN
SELECT (x)
ENDIF
**************End MarkPrimary.prg*******************
- Run the MarkPrimary.prg code by typing the following into the
Command window:
DO MARKPRIMARY WITH "MYTEST"
- Modify the view MyTest in the View Designer and notice that the primary
key field is now marked for updates.
APPLIES TO
- Microsoft Visual FoxPro 5.0 Standard Edition
- Microsoft Visual FoxPro 5.0a
- Microsoft Visual FoxPro 6.0 Professional Edition
- Microsoft Visual FoxPro 3.0b for Macintosh
- Microsoft Data Access Components 2.5
| kbcode kbdatabase kbhowto KB174689 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate