在 Visual Foxpro 6 中更新光标值

问题描述 投票:0回答:1

我在 Visual Foxpro 6 中创建了一个光标,如下所示。

select month, memid, mname, bt, st, bh, sh, totk, toth, sum(totk*0.025)/100 as laga, sum(toth*0) as hchg, sum(totk*0.050)/100 as Tax ;
from abc2 ;
group by memid ;
order by 2 ;
into curs abc3


IF !USED("abc3")
USE abc3 in 0
ENDIF

select abc3 
go top
do while not eof()
update abc3 set month =  Thisform.txtReportHeader.Value
skip
ENDDO

“update abc3 set Month = Thisform.txtReportHeader.Value”行给了我一个错误,说我无法更新光标。如何使用文本字段“Thisform.txtReportHeader.Value”的值更新此列?

visual-foxpro
1个回答
1
投票

要使游标可更新,您需要使用 READWRITE 子句。即:

select * from myTable into cursor crsX READWRITE

但是,如果我没记错的话,READWRITE是在VFP7中引入的。如果是正确的,那么您应该使用老技巧使其可更新:

  • 首先选择它成为真正的光标。您可以通过简单地添加 NOFILTER 子句来做到这一点(在旧版本中,如 VFP5,添加类似 WHERE .T. 的内容即可)。
  • 然后在另一个工作区域再次使用光标。

所以你的代码变成:

Select Month,memid,mname,bt,st,bh,sh,totk,toth,Sum(totk*0.025)/100 As laga,Sum(toth*0) As hchg,Sum(totk*0.050)/100 As Tax ;
    from abc2 ;
    group By memid ;
    order By 2 ;
    into Curs abc3_tmp ;
    nofilter
    
USE DBF('abc3_tmp') IN 0 AGAIN ALIAS abc3   

Update abc3 Set Month =  Thisform.txtReportHeader.Value

* You don't need to select it to update it. 
* And you also don't need a loop to do that
* If you wanted to limit the updated rows you would use a WHERE clause

*Select abc3 

PS:虽然这种 SQL 在 VFP7 及更早版本中可以工作并且不会给出错误,但请尝试编写有效的 SQL,不要有任何歧义。也就是说,将所有非聚合列包含在分组依据中。如果不能,请三思,您的查询可能有问题。

© www.soinside.com 2019 - 2024. All rights reserved.