Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating records in a table from a cursor
Message
From
27/10/2005 07:54:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01062560
Message ID:
01062577
Views:
14
>I have aan SQL query which is run when a user clicks a button. A readwrite cursor is created and used to populate a grid. When the user make the change I want to then update the changes made to the cursor to the main table. I could scan all records in the cursor and update the main table but this is pointless I feel. Is is best to have a field say changed and set all records to 0 when running the query.
>
>Then I thought if they change the record it set the field to 1. Then when they click save I could then scan the table where change = 1 and then do the update.
>
>Is this viable?

Neil,
I think this is related with your other 'crosstab' question. You could use CursorSetProp() with grid's source cursor. ie:

CursorSetProp("Buffering",5,"gridSource")

When users change the data you would then have a way to loop modified records with GetNextModified(). ie:
lnRecNo = GetNextModified(0,"gridSource")
do while m.lnRecno # 0
* if m.lnRecno < 0 && Added record
* AddRecord()
* else  && Edited record
* UpdateRecord()
* endif
 UpdateRecord() && Handling both insert and update
 lnRecNo = GetNextModified(m.lnRecNo,"gridSource")
enddo
UpdateRecord might look like this:
Procedure UpdateRecord
AddUpdate('GridSource','Style','Costed')
AddUpdate('GridSource','Style','Cut')
AddUpdate('GridSource','Style','Made')
endproc

Procedure AddUpdate(tcSource,tcStyle,tcActivity)
local lnSelect
local Style,Activity,ActualDate
Style = eval(m.tcSource+'.'+m.tcStyle)
Activity = upper(m.tcActivity)
ActualDate = eval(m.tcSource+'.'+m.tcActivity)
if isnull(m.ActualDate)
 return
endif
lnSelect = select()
select myBaseTable
locate for Style = m.Style and upper(Activity) = m.Activity
if eof()
  insert into myBaseTable from memvar
else
  gather fields ActualDate memvar
endif
select (m.lnSelect)
endproc
You might cut the time it needs instead having UpdateCode() in afterrowcolchange with checking if it was a Row Change.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform