PB DataWindow 不需要 DataObject 的查询方法

本文介绍了一种通过Tree View Item获取数据库表名,并根据表名动态生成SQL查询语句的方法。此方法能根据Tree View Item中选择的内容从数据库中查找对应表的信息,并进一步获取表的所有字段名称,最终形成完整的查询语句。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[code="python"]TreeViewItem cdItem

tv_1.GetItem(handle,cdItem)

long finded

String tablelabel,tablename


tablelabel = cdItem.Label

if tablelabel "" Then

select count(*)

into:finded

from pbcattbl

where pbt_cmnt = :tablelabel;

select pbt_tnam

into:tablename

from pbcattbl

where pbt_cmnt = :tablelabel;

if finded = 0 Then

select count(*)

into:finded

from pbcattbl

where pbt_tnam = :tablelabel;

tablename = tablelabel

end if



if finded >= 1 Then



string ls_syntax,ls_sql,ls_error,colname,collabel

long ls_rowcount,i

//查找要显示的字段

ls_sql ="SELECT pbc_cnam,pbc_cmnt FROM pbcatcol where pbc_tnam = '"+tablename+"'"

ls_syntax =sqlca.syntaxfromsql(ls_sql, ' ',ls_error)



if len(ls_error)>0 then messagebox("错误",ls_error)



dw_3.create(ls_syntax,ls_error)



if len(ls_error)>0 then messagebox("错误",ls_error)



dw_3.settransobject(sqlca)

dw_3.retrieve()



ls_rowcount = dw_3.RowCount()


ls_sql ="SELECT "

for i = 1 to ls_rowcount

ls_sql= ls_sql + dw_3.GetItemString(i,1)

if i ls_rowcount Then

ls_sql = ls_sql + ","

end if

next

ls_sql = ls_sql + " FROM "+tablename

ls_syntax =sqlca.syntaxfromsql(ls_sql, ' ',ls_error)



if len(ls_error)>0 then messagebox("错误",ls_error)



dw_1.create(ls_syntax,ls_error)



if len(ls_error)>0 then messagebox("错误",ls_error)

*/


dw_1.settransobject(sqlca)

dw_1.modify("IF(MOD(GETROW(),2)=0,RGB(192, 192, 192), RGB(255, 255, 255))")

dw_1.retrieve()



//THIS.PostEvent("ue_postopen")

else

MessageBox("错误","数据库中没有该表")

end if



end if[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值