PowerBuilder 数据窗口实例四(用户信息查询)
1. 设计数据窗口
2.设置table order值与更新属性(详见之前博客)
3. 设计查询窗体,并保存为w_userinfo_find
4. 在查询按钮的clicked()事件添加如下代码
//定义变量
string find_colum
string find_sign
string find_content
string find_condition
integer current_row
integer total_row
integer find_row
//赋值
if ddlb_1.text = "用户名" then
find_colum = "username"
elseif ddlb_1.text = "性别" then
find_colum = "sex"
elseif ddlb_1.text = "地址" then
find_colum = "address"
end if
find_sign = ddlb_2.text
find_content = sle_1.text
find_condition = find_colum + find_sign +"'"+find_content+"'"
// 得到行号
current_row = dw_1.getrow( )
// 得到总行数
total_row = dw_1.rowcount()
//从当前行查起到最后记录
find_row = dw_1.find(find_condition, current_row, total_row)
if find_row > 0 then
dw_1.selectrow(0, false)
dw_1.selectrow(find_row,true)
end if
5. 在退出按钮添加如下代码
close(w_userinfo_find)
如我们查一条姓名为zhanglei的数据:
6. 查询还可以用filter实现
//定义变量
string find_colum
string find_sign
string find_content
string find_condition
integer current_row
//integer total_row
//integer find_row
//赋值
if ddlb_1.text = "用户名" then
find_colum = "username"
elseif ddlb_1.text = "性别" then
find_colum = "sex"
elseif ddlb_1.text = "地址" then
find_colum = "address"
end if
find_sign = ddlb_2.text
find_content = sle_1.text
find_condition = find_colum + find_sign +"'"+find_content+"'"
/* 得到行号
current_row = dw_1.getrow( )
// 得到总行数
total_row = dw_1.rowcount()
//从当前行查起到最后记录
find_row = dw_1.find(find_condition, current_row, total_row)
if find_row > 0 then
dw_1.selectrow(0, false)
dw_1.selectrow(find_row,true)
end if
*/
dw_1.setfilter(find_condition)
dw_1.filter()