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

Power Apps使用Patch函数更新SQL记录时,主键匹配仍报指定记录未找到错误

解决Power Apps Patch更新SQL Server时「指定记录未找到」的问题

问题场景

尝试用Power Apps的Patch函数更新SQL Server表记录,已添加SQL Server连接,编写代码如下:

Patch(
    myTable,
    LookUp(myTable, itemKey = myItemKey),
    {
    otherField: TextInput.Text
    }
);

最初因SQL表未设置主键报错,将itemKey设为表主键后,又出现错误:

Network error when using Patch function:specified record was not found

已确认Patch中的字段名与SQL列名完全匹配,但错误仍存在。

解决方案

经过调试,总结以下几个可能的原因及解决办法:

1. 主键数据类型不匹配

如果SQL Server表的主键是数值类型(如int、bigint),但Power Apps中myItemKey是字符串类型,会导致LookUp无法匹配到记录。
解决:将myItemKey转换为对应数值类型,示例:

Patch(
    myTable,
    LookUp(myTable, itemKey = Value(myItemKey)),
    {
    otherField: TextInput.Text
    }
);

2. LookUp返回空记录

可能myItemKey的值在表中不存在,或者字符串主键存在大小写/多余空格问题:

  • 先单独运行LookUp(myTable, itemKey = myItemKey)验证是否返回有效记录;
  • 若为字符串主键,用Trim()处理多余空格:
Patch(
    myTable,
    LookUp(myTable, itemKey = Trim(myItemKey)),
    {
    otherField: TextInput.Text
    }
);

3. 权限或表主键配置问题

  • 确认Power Apps连接的SQL账号拥有该表的更新权限;
  • 检查SQL Server表的主键是否正确定义(需在SQL中设置,而非仅在Power Apps连接中标记)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 10:57:28