Microsoft KB Archive/174689: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - "&" to "&")
 
(One intermediate revision by the same user not shown)
Line 88: Line 88:


<ol>
<ol>
<li>Open the Tastrade database in the VFP\Samples\Tastrade\Data folder in Visual FoxPro 5.0, or the home(2)+&quot;Tastrade\Data&quot; folder in Visual FoxPro 6.0.</li>
<li>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.</li>
<li><p>Run the following program to create a new SQL view based on the Customer table. <span class="kbd userinput"> </span></p>
<li><p>Run the following program to create a new SQL view based on the Customer table. <span class="kbd userinput"> </span></p>
<pre class="codesample">      ***********RunFirst.prg***********
<pre class="codesample">      ***********RunFirst.prg***********
       CREATE SQL VIEW MYTEST AS SELECT * FROM CUSTOMER
       CREATE SQL VIEW MYTEST AS SELECT * FROM CUSTOMER
       DBSETPROP(&quot;MYTEST&quot;,&quot;VIEW&quot;,&quot;SENDUPDATES&quot;,.T.)
       DBSETPROP("MYTEST","VIEW","SENDUPDATES",.T.)
       ***********End RunFirst.prg*************
       ***********End RunFirst.prg*************
                             </pre></li>
                             </pre></li>
Line 101: Line 101:


       x=ALIAS()
       x=ALIAS()
       USE IN 0 &amp;viewname
       USE IN 0 &viewname
       PrimKeys = CURSORGETPROP('KeyFieldList',viewname)
       PrimKeys = CURSORGETPROP('KeyFieldList',viewname)
       i=1
       i=1
       remField=PrimKeys
       remField=PrimKeys
       DO WHILE i <> 0
       DO WHILE i <> 0
         nextcomma=AT(remField,&quot;,&quot;)
         nextcomma=AT(remField,",")
         IF nextcomma=0 and len(remfield)=0 THEN
         IF nextcomma=0 and len(remfield)=0 THEN
             i=0
             i=0
Line 113: Line 113:
             IF nextcomma=0 and LEN(remfield)<>0 then
             IF nextcomma=0 and LEN(remfield)<>0 then
               tmpfield=remfield
               tmpfield=remfield
               y= DBSETPROP(ViewName + &quot;.&quot; + ;
               y= DBSETPROP(ViewName + "." + ;
               tmpField,'Field','UPDATABLE',.T.)
               tmpField,'Field','UPDATABLE',.T.)
               i=0
               i=0
Line 121: Line 121:
               remfield=SUBSTR(remfield,nextcomma + 1)
               remfield=SUBSTR(remfield,nextcomma + 1)
               i=nextcomma
               i=nextcomma
               y= DBSETPROP(ViewName + &quot;.&quot; + ;
               y= DBSETPROP(ViewName + "." + ;
               tmpField,'Field','UPDATABLE',.T.)
               tmpField,'Field','UPDATABLE',.T.)
             ENDIF
             ENDIF
Line 135: Line 135:
                             </pre></li>
                             </pre></li>
<li><p>Run the MarkPrimary.prg code by typing the following into the Command window: <span class="kbd userinput"> </span></p>
<li><p>Run the MarkPrimary.prg code by typing the following into the Command window: <span class="kbd userinput"> </span></p>
<pre class="codesample">      DO MARKPRIMARY WITH &quot;MYTEST&quot;
<pre class="codesample">      DO MARKPRIMARY WITH "MYTEST"
                             </pre></li>
                             </pre></li>
<li>Modify the view MyTest in the View Designer and notice that the primary key field is now marked for updates.</li></ol>
<li>Modify the view MyTest in the View Designer and notice that the primary key field is now marked for updates.</li></ol>

Latest revision as of 12:30, 21 July 2020

Article ID: 174689

Article Last Modified on 2/16/2005



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



This article was previously published under Q174689

SUMMARY

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.

MORE INFORMATION

View Designer

To mark the primary key as updateable through the View Designer interface, use the following steps:

  1. Open the view in the View Designer.
  2. Click the Update Criteria tab.
  3. 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:

  1. 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.
  2. 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*************
                                
  3. Modify the view in the View Designer and note that the primary key is not marked for updates.
  4. 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*******************
                                
  5. Run the MarkPrimary.prg code by typing the following into the Command window:

          DO MARKPRIMARY WITH "MYTEST"
                                
  6. Modify the view MyTest in the View Designer and notice that the primary key field is now marked for updates.


Keywords: kbhowto kbdatabase kbcode KB174689