关于数据窗口多表更新

wlinglong 2008-04-29 05:34:47
程序中有2个数据窗口控件 dw_1,dw_2

2个数据窗口挂接的数据窗口的结构都是一样的, d_one,d_two
d_one 的语句是 Select A.a,A.b,B.c,B.d From A,B Where A.a = B.a
2个数据窗口控件都不存在插入操作, 只有修改和更新,有多条修改的操作。
现在如何同时更新 A表和B表。

我现在的做法: dw_1.Sharedata(dw_2)
然后更改 d_one和d_two的UPDATE 属性,dw_1 里面更新A表, dw_2里面更新B表, 但是总是 A表更新 B表不更新,
希望高手帮忙解决
...全文
209 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
UltraBejing 2008-05-01
  • 打赏
  • 举报
回复
不知,帮顶
suntoto 2008-04-30
  • 打赏
  • 举报
回复
dw1update 的clicked 事件写以下语句
dw2update.TriggerEvent(Clicked!)

dw1update,dw1update 为两窗口更新按钮。
wlinglong 2008-04-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sdhylj 的回复:]
还没结啊,看来五一前升不了了.
[/Quote]

哥们 不好意思 业务太忙了, 刚结贴 窗口开了2个多小时 没动了
青锋-SS 2008-04-30
  • 打赏
  • 举报
回复
还没结啊,看来五一前升不了了.
dawugui 2008-04-29
  • 打赏
  • 举报
回复
数据窗口修改多个表

  当数据窗口中的数据来自不同的数据表时,一般只让用户查看数据,或者只让用户修改其中一个数据表中的数据,这样可以不用编写任何脚本就能实现。但是,特殊情况下需要修改多个数据表中的数据,因为数据窗口对象不能同时修改两个数据表,只能编写脚本来实现该功能。
  用脚本实现一个数据窗口对象修改多个数据表的数据,编程思想是动态修改数据窗口的Update相关属性。实际上,数据窗口修改数据表是根据在DataWindow画板中指定的属性进行修改的,这些属性在运行时可以由脚本修改,从而让数据窗口修改完一个数据表后再修改另一个数据表,直到修改完所有需要修改的数据表。需要注意的一点是,数据窗口中每一行都有一个修改标志(可以使用函数GetItemStatus 来读取该标志),当数据提交后数据窗口自动清除该标志,所以当需要修改多个数据表时,在没有修改完所有的数据表之前不能清除每一行的标志。函数dwcontrol.Update ( { accept {, resetflag } } )中的参数resetflag为boolean类型,取值为False表示不修改数据行的行标志。下面的脚本示例了在一个DataWindow中修改它所对应的多个表,该数据窗口的字段来自两个表,语句如下:
  SELECT department.dept_id, department.dept_name,employee.emp_id, employee.emp_fname,employee.emp_lname FROM department, employee
  在创建数据窗口时设置为Department表可修改。所以,程序运行时可以首先修改Department表,如果修改数据表成功,则进行第二个数据表的修改。首先设置要修改第二个数据表的哪些字段、哪些字段作为主键、要修改的数据表表名,然后使用Update语句开始修改数据表。如果第二个数据表修改成功,则再修改第三个数据表,直到修改完所有的数据表。在本例中只有两个数据表要修改,脚本如下:
  Int li_ResultUpdate
  li_ResultUpdate = dw_1.Update(True,False)//接受最后一个字段内容,并且不清除行修改标志
  //如果对Department表的修改成功,下一步就要修改另一个表Employee
  If li_ResultUpdate = 1 Then
   //首先,关掉对Department表的修改
   dw_1.ModIfy('department_dept_name.Update = "No"')
   dw_1.ModIfy('department_dept_id.Update = "No"')
   dw_1.ModIfy('department_dept_id.Key = "No"')
   //使Employee表成为新的可修改表
   dw_1.dwModIfy('DataWindow.Table.UpdateTable = ~'employee~' ')
   dw_1.ModIfy('employee_emp_id.Update = "Yes"')
   dw_1.ModIfy('employee_emp_fname.Update = "Yes"')
   dw_1.ModIfy('employee_emp_lname.Update = "Yes"')
   dw_1.ModIfy('employee_emp_id.Key = 'Yes' ' )
   //然后修改Employee表
   li_ResultUpdate = dw_1.Update()
    If li_ResultUpdate = 1 Then
     Commit Using SQLCA;
    Else
     MessageBox("修改错误!", "数据修改错误,错误代码" + String(SQLCA.SqlDBCode) + "~r~n错误原因:" + SQLCA.SqlErrText)
     Rollback Using SQLCA;
    End If
   //恢复数据窗口开始时的属性,以便下一次用户点击“保存”按钮时
   //程序能够正确执行
   dw_1.ModIfy('department_dept_name.Update = "Yes"')
   dw_1.ModIfy('department_dept_id.Update = "Yes"')
   dw_1.ModIfy('department_dept_id.Key = "Yes"')
   dw_1.ModIfy('DataWindow.Table.UpdateTable = ~'department~' ')
   dw_1.ModIfy('employee_emp_id.Update = "No" ')
   dw_1.ModIfy('employee_emp_fname.Update = "No" ')
   dw_1.ModIfy('employee_emp_lname.Update = "No'' ')
   dw_1.ModIfy('employee_emp_id.Key = "No" ')
  Else
   MessageBox('Update of department table failed', 'Rolling back changes To department')
   Rollback Using SQLCA;
  End If

编程夜猫 2008-04-29
  • 打赏
  • 举报
回复
以下的楼层正解,哈哈哈
青锋-SS 2008-04-29
  • 打赏
  • 举报
回复

//只使用一个数据窗口dw_1
//Select A.a,A.b,B.c,B.d From A,B Where A.a = B.a
int rc
dw_1.Modify("DataWindow.Table.UpdateTable = ~"A~" a_a.update = yes a_b.update = yes a_a.key = yes") //如果A表的主键不是a,刚此处的a_a.key应该修改为:a_实际主键列的名称.key = yes
rc = dw_1.Update(true,false)
if rc = 1 then //A表保存成功
dw_1.Modify("DataWindow.Table.UpdateTable = ~"B~" b_c.update = yes b_d.update = yes b_c.key = yes") //如果B表的主键不是c,刚此处的b_c.key应该修改为:b_实际主键列的名称.key = yes
dw_1.Update()
end if
青锋-SS 2008-04-29
  • 打赏
  • 举报
回复

只使用一个数据窗口dw_1
//Select A.a,A.b,B.c,B.d From A,B Where A.a = B.a
dw_1.Modify("DataWindow.Table.UpdateTable = ~"A~" a_a.update = yes a_b.update = yes a_a.key = yes")
dw_1.Update(true,false)
dw_1.Modify("DataWindow.Table.UpdateTable = ~"B~" b_c.update = yes b_d.update = yes b_c.key = yes")
dw_1.Update()
青锋-SS 2008-04-29
  • 打赏
  • 举报
回复

Updating more than one table
An important use of Modify is to make it possible to update more than one table from one DataWindow object.
The following script updates the table that was specified as updatable in the DataWindow painter;
then it uses Modify to make the other joined table updatable and to specify the key column and which columns to update.
This technique eliminates the need to create multiple DataWindow objects or to use embedded SQL statements
to update more than one table.

In this example, the DataWindow object joins two tables: department and employee.
First department is updated, with status flags not reset.
Then employee is made updatable and is updated. If all succeeds,
the Update commands resets the flags and COMMIT commits the changes.
Note that to make the script repeatable in the user's session, you must add code to make department the updatable table again:

integer rc

string err

/* The SELECT statement for the DataWindow is:

SELECT department.dept_id, department.dept_name,

employee.emp_id, employee.emp_fname,

employee.emp_lname FROM department, employee ;

*/

// Update department, as set up in the DW painter

rc = dw_1.Update(TRUE, FALSE)

IF rc = 1 THEN
//Turn off update for department columns.
dw_1.Modify("department_dept_name.Update = No")
dw_1.Modify("department_dept_id.Update = No")
dw_1.Modify("department_dept_id.Key = No")

// Make employee table updatable.
dw_1.Modify("DataWindow.Table.UpdateTable = ~"employee~"")

//Turn on update for desired employee columns.
dw_1.Modify("employee_emp_id.Update = Yes")
dw_1.Modify("employee_emp_fname.Update = Yes")
dw_1.Modify("employee_emp_lname.Update = Yes")
dw_1.Modify("employee_emp_id.Key = Yes")

//Then update the employee table.
rc = dw_1.Update()
IF rc = 1 THEN
COMMIT USING SQLCA;
ELSE
ROLLBACK USING SQLCA;
MessageBox("Status","Update of employee table failed.Rolling back all changes.")
END IF

ELSE
ROLLBACK USING SQLCA;
MessageBox("Status","Update of department table failed.Rolling back changes to department.")

END IF
青锋-SS 2008-04-29
  • 打赏
  • 举报
回复
一个数据窗口就可以了,用Modify()修改可更新的表.

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧