PB中数据库字段中存取图片的实例

来源:互联网 发布:网红林珊珊淘宝店铺 编辑:程序博客网 时间:2024/05/22 17:24
 

最近有些网友问及在数据库的字段来存取图片,下面我将曾经做的一个实例放在下面,希望能给大家有帮助.

建一个表,表结构如下:

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)dw_1.retrieve()

在dw_1的clicked事件中

if row >0 thenlong llll=this.object.id[row]ll_id=llwf_display_image(ll)end if

在dw_1的retrieveend事件中

if rowcount >0 thenthis.scrolltorow(1)long llll=this.object.id[1]ll_id=llwf_display_image(ll)end if

建一个函数wf_display_image,参数为as_id 类型numeric

Blob Emp_id_picSELECTBLOB pictureINTO :Emp_id_pic FROM img_testWHERE id=:as_id;if isnull(len(emp_id_pic)) or len(emp_id_pic)=0 then elsep_1.SetPicture(Emp_id_pic)end if

在cb_1的clicked事件中

openwithparm(w_picture,'1',parent)gs_commodity s_returns_return=message.powerobjectparmstring ls_filenamels_filename=s_return.picture_nameis_filename=ls_filename//(以上代码中引用了一个结构,结构中picture_name 类型为string,可以不用结构,直接返回一个字符串。)


在cb_2的clicked事件中

UPDATEBLOB img_test SET picture = :iEmp_id_picWHERE id = :ll_id;IF sqlca.SQLNRows > 0 THENCOMMIT ;messagebox('a','ok')Elsemessagebox('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_returns_return.commodityid=is_commodityids_return.picture_name=is_newfilenames_return.update_type=is_update_typelong l_1l_1 = closewithreturn(parent ,s_return)


在cb_cancel的clicked事件中

is_update_type='0'gs_commodity s_returns_return.commodityid=is_commodityids_return.update_type=is_update_typeclosewithreturn(parent,s_return)


原创粉丝点击