下面的脚本示例了在一个DataWindow中修改它所对应的多个表,
int rc
string err
DataWindow建立了两个表Department和Employee的Join之上,它的Select语句为:
SELECT department.dept_id, department.dept_name,
employee.emp_id, employee.emp_fname,
employee.emp_lname FROM department, employee
在开始设置为对Department表可修改。所以,可以首先修改Department表,设置Reset标志,
以便对表的修改不改变数据窗口的行列状态(假设使用的是SetTransObject,以便对数据库的
修改不会自动提交)
rc = dw_1.Update(true,false)
//如果对Department表的修改成功,下一步就要修改另一个表
IF rc = 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表
rc = dw_1.Update()
IF rc = 1 THEN
COMMIT USING SQLCA;
ELSE
MessageBox(Update of employee table failed, Rolling back changes to & department and employee)
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
int rc
string err
DataWindow建立了两个表Department和Employee的Join之上,它的Select语句为:
SELECT department.dept_id, department.dept_name,
employee.emp_id, employee.emp_fname,
employee.emp_lname FROM department, employee
在开始设置为对Department表可修改。所以,可以首先修改Department表,设置Reset标志,
以便对表的修改不改变数据窗口的行列状态(假设使用的是SetTransObject,以便对数据库的
修改不会自动提交)
rc = dw_1.Update(true,false)
//如果对Department表的修改成功,下一步就要修改另一个表
IF rc = 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表
rc = dw_1.Update()
IF rc = 1 THEN
COMMIT USING SQLCA;
ELSE
MessageBox(Update of employee table failed, Rolling back changes to & department and employee)
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