You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VFP 8更新SQL Server数据仅修改一行,请求修正脚本

VFP 8更新SQL Server数据脚本修正方案

原脚本执行后仅更新一行数据,核心问题是未遍历游标所有记录,同时存在表名拼写错误和变量遗漏赋值的问题,以下是修正后的完整代码:

原代码问题点

  • 变量赋值时表名拼写错误:skedule1应为skedul1
  • 遗漏m.value4 = skedul1.pokok_sd的赋值,导致UPDATE语句中pokok_sd字段无有效值
  • 未循环遍历游标skedul1的所有记录,仅处理了当前第一条记录

修正后的完整代码

create cursor skedul1 (norekening N(13), ke N(2), pokok_kr N(12), bunga_kr N(12), pokok_sd N(12))
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 1, 0, 26400, 850000)
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 2, 0, 26400, 850000)
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 3, 0, 26800, 850000)
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 4, 0, 26400, 850000)
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 5, 0, 25500, 850000)
insert into skedul1 (norekening, ke, pokok_kr, pokok_sd, bunga_kr) values (1312124120052, 6, 850000, 26400, 0)

select skedul1
* 遍历游标所有记录
scan
    m.value1 = skedul1.norekening
    m.value2 = skedul1.ke
    m.value3 = skedul1.pokok_kr
    m.value4 = skedul1.pokok_sd  && 补充遗漏的变量赋值
    m.value5 = skedul1.bunga_kr

    TEXT TO m.lcSQL TEXTMERGE noshow
    UPDATE dbo.skedul
    SET pokok_kr = ?m.value3,
        pokok_sd = ?m.value4,
        bunga_kr = ?m.value5
    WHERE norekening = ?m.value1 and ke = ?m.value2
    ENDTEXT

    lnResult = SQLExec(Thisform.nHandle, m.lcSQL)
    If m.lnResult < 0
        Aerror(aWhy)
        Messagebox(aWhy[2])
        SQLDisconnect(0)
        Return .F.
    Endif
endscan

* 所有记录更新完成后提示
Messagebox("Data Telah Update..!!")
thisform.PopulateGrid()
thisform.grid2.RecordSource = ""

修正说明

  1. 添加scan...endscan循环,遍历游标skedul1的每一条记录,逐条执行UPDATE操作
  2. 修正变量赋值时的表名错误,统一使用skedul1
  3. 补充m.value4 = skedul1.pokok_sd的赋值,确保UPDATE语句中pokok_sd字段有正确值
  4. 将成功提示移到循环外,避免每更新一条就弹出提示

内容的提问来源于stack exchange,提问作者albharons

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 14:53:18