如何从livecode datagrid中的更改更新数据库

时间:2015-09-13 21:05:52

标签: datagrid livecode

我在livecode中有一个datagrid。我希望在用户对datagrid的一行进行更改后更新底层数据库中的数据

嗨,马尔特,

这看起来很有希望。唯一的问题是数据库表中的名称字段与列名称不同。我想使用sql update语句来更新数据库。我尝试了以下代码

on CloseFieldEditor pFieldEditor

--Connect to database
  databaseConnect
--Update Record

put  GetDataOfLine( the dgHilitedlines of me,"Pathogen") into strPathogen
put  GetDataOfLine( the dgHilitedlines of me,"Offset") into strIncubation
put  GetDataOfLine( the dgHilitedlines of me,"Duration") into     strDurationofIllness
put  GetDataOfLine( the dgHilitedlines of me,"ID") into IntID

put "UPDATE  tblPathogen SET fldPathogenName='" & strPathogen & "',     fldIncubation='" & strIncubation &  "', fldDurationofIllness='" &     strDurationofIllness & "'" into strSQL
put " WHERE fldPathogenID=" & IntID after strsql

put strsql into field "test"

--SaveDataToDatabase theTable, theRowID, theColumnBeingEdited, theNewText

end CloseFieldEditor    

问题是网格中的值在分配给变量之前会变回原始值。如何更新网格以保存pFieldEditor

的文本

1 个答案:

答案 0 :(得分:1)

如果未使用自己的模板覆盖标准数据网格行为,则会向网格控件发送CloseFieldEditor消息。您可以使用该消息来响应数据更改并触发将数据存储在数据库中的处理程序。

这里的问题是你捕获实际更新数据网格的处理程序。在常规情况下,数据网格的数据在消息执行后更新。因此,在您的情况下,您将需要自己更新数据...

修改过的脚本:

 for letter1, letter2 in message:
        if letter1.isalpha() and letter2.isalpha():
            positions = [(alphabet.find(m), alphabet.find(n)) for m, n in message]

这里解释得非常好:http://lessons.runrev.com/m/datagrid/l/7337-how-do-i-save-changes-the-user-makes-in-an-editor-field-to-an-external-data-source

请记住,脚本并未针对严格的编译模式进行优化(我总是建议使用它,因为它可以让您免于拍摄自己的脚)。如果希望脚本在严格模式下编译,则还需要声明变量。

相关问题