powerbuilder9.0之datawindow的update(我的PB学习第二十天)

来源:互联网 发布:电脑日程安排软件 编辑:程序博客网 时间:2024/05/21 07:59
hehe

近两三天来,都苦闷于datawindow的update数据库未果,求助数人,大家给的也只是一些有可能的tip.最多的是修改update属性,偶也试了,describe(columnname.update)都已经等于yes了,还是提示说没有update ability.群里有人提示key也要是yes,俺也就去modify(key =yes)结果还是不可以.接近放弃了.想了想,还是看看表结果有没有设置primary key,结果发现没有,改了表结构再试,终于可以了.

有时候真的是会被自己的低级错误给搞死哦~

下面俺就随便说说,关于update的吧

背景介绍: dw_src是源数据窗口,dw_target动态绑定数据对象a,所做操作把dw_src拷贝到dw_target,然后更新dw_target.其中要注意的就是a的结构与dw_src的数据对象结构要一致.还有a 要有primary key

源码:

long ll_col_count,ll_i
string ls_column[],ls_column_type[],sql

ll_col_count = long(dw_test.Describe("Datawindow.Column.count"))

//取得源数据窗口的列名,及类型
for ll_i=1 to ll_col_count
 if dw_src.Describe("#"+string(ll_i)+".visible")='1' then
  //列名
  ls_column[ll_i]=dw_src.describe("#"+string(ll_i)+".Name")
  //列类型
  ls_column_type[ll_i]=dw_src.Describe(ls_column[ll_i]+".Coltype") 
 end if
next

//动态绑定表a
String Errors
sql="select * from a"
dw_target.Create(sqlca.SyntaxFromSql (Sql,"style(type=grid)",Errors))

If Len(Errors)>0 then
 MessageBox("注意","发生错误:"+Errors)
end if
 dw_target.settransobject(sqlca)
 dw_target.retrieve()

//修改update属性=yes
 for ll_i=1 to ll_col_count
      dw_target.modify(ls_column[ll_i]+".update='yes' "+ls_column[ll_i]+".updatewhereclause='yes' ")
next

if dw_target.AcceptText() = -1 then return end if


 //行拷贝
if dw_src.RowsCopy(1, dw_src.RowCount(), Primary!, dw_target, 1, Primary!) = 1 then
 messagebox("提示","拷贝成功")
else
 messagebox("提示","拷贝失败")
end if

if dw_target.update()=1 then
 messagebox("提示","保存成功") 
else
 messagebox("提示","保存失败")
end if

原创粉丝点击