PB中数据库字段中存取图⽚的实例
最近有些⽹友问及在数据库的字段来存取图⽚,下⾯我将曾经做的⼀个实例放在下⾯,希望能给⼤家有帮助.
建⼀个表,表结构如下:
id numberic 8,img_text varchar 20,picture image . id为主键
在PB中新建⼀个窗⼝,保存为w_image_test,在窗⼝中放置⼀个DW控件dw1,⼀个IMAGE控件p_1,3个按钮cb_1,cb_2,cb_3,分别是浏览、更新、退出,如下图所⽰:
在窗体的open事件中,代码如下:
dw_1.settransobject(sqlca)
ieve()
在dw_1的clicked事件中
if row >0 then
long ll
ll=this.object.id[row]
ll_id=ll
wf_display_image(ll)
end if
在dw_1的retrieveend事件中
if rowcount >0 then
this.scrolltorow(1)
long ll
ll=this.object.id[1]
ll_id=ll
wf_display_image(ll)
end if
建⼀个函数wf_display_image,参数为as_id 类型numeric
Blob Emp_id_pic
SELECTBLOB picture
INTO :Emp_id_pic
FROM img_test
WHERE id=:as_id
;
if isnull(len(emp_id_pic)) or len(emp_id_pic)=0 then
else
p_1.SetPicture(Emp_id_pic)
end if
在cb_1的clicked事件中
openwithparm(w_picture,'1',parent)
gs_commodity s_return
s_return=message.powerobjectparm
string ls_filename
ls_filename=s_return.picture_name
is_filename=ls_filename
//(以上代码中引⽤了⼀个结构,结构中picture_name 类型为string,可以不⽤结构,直接返回⼀个字符串。)
在cb_2的clicked事件中
UPDATEBLOB img_test SET picture = :iEmp_id_pic
WHERE id = :ll_id;
IF sqlca.SQLNRows > 0 THEN
COMMIT ;
messagebox('a','ok')
Else
messagebox('b','cancel')
end if
再新建⼀个窗体,⽤于查要保存的图⽚⽂件,将新窗体保存为w_picture,在该窗体中放上⼀个listbox控件lb_file_list,⼀个image控件p_picture,2个按钮cb_ok,cb_cancel,分别为确定及取消。如下图所⽰:
在窗体的open事件中
lb_file_list.dirlist("c:\picture\*.jpg",0)
在lb_file_list的selectionchanged事件中
is_update_type='1'
is_newfilename=lb_file_list.selecteditem()
p_picture.picturename="c:\picture\" + is_newfilename
在cb_ok的clicked事件中
gs_commodity s_return
s_returnmodityid=is_commodityid
s_return.picture_name=is_newfilename
s_return.update_type=is_update_type
long l_1
isnull的用法
l_1 = closewithreturn(parent ,s_return)
在cb_cancel的clicked事件中
is_update_type='0'
gs_commodity s_return
s_returnmodityid=is_commodityid
s_return.update_type=is_update_type
closewithreturn(parent,s_return)