//**************************************************************** “选择”按钮代码: lb_image = gf_open_pic(p_1,lb_image) p_1.setpicture(lb_image) //*************************************************************** “清除”按钮代码: p_1.picturename = '' p_1.picturename = ''//(需要两次) setnull(lb_image) //*************************************************************** 函数gf_open_pic: ////////////////////////////////////////////////////////////////// //Add by Jeffrey Jiang on 2001.11.13 //选择图片 ///////////////////////////////////////////////////////////////// //Modfiy by Jeffrey Jiang on 2001.11.15 //当图片字节大于32765时,循环读图片 ///////////////////////////////////////////////////////////////// integer li_file,li_ret,loops,i string ls_file,ls_path blob lb_small long flen,bytes_read,new_pos //search the file li_ret = getfileopenname("选择图片文件",ls_path,ls_file, & "BMP","图片文件(*.BMP),*.BMP") if li_ret = 1 then p_1.picturename = '' p_1.picturename = '' setnull(lb_image) if li_file <> -1 then // Set a wait cursor setpointer(hourglass!) flen = filelength(ls_file) li_file = fileopen(ls_path,streammode!,read!,lockread!) // Determine how many times to call FileRead if flen > 32765 then if mod(flen,32765)=0 then loops = flen/32765 else loops = (flen/32765) + 1 end if else loops = 1 end if // Read the file new_pos = 1 for i = 1 to loops bytes_read = fileread(li_file,lb_small) if i = 1 then lb_image = lb_small else lb_image = lb_image + lb_small end if next // close the file fileclose(li_file) end if end if return lb_image //*************************************************************** 保存按钮代码: UPDATEBLOB "person" SET "person"."PHOTO" = :lb_image WHERE "person"."C_ID" = :ls_c_id USING SQLCA; IF sqlcadoor.SQLNRows > 0 THEN commit using sqlca; END IF //*************************************************************** 显示图片: lb_image = f_select_pic(ls_c_id) p_1.setpicture(lb_image) //*************************************************************** f_select_pic函数: blob lb_image setnull(lb_image) selectblob "person"."PHOTO" into:lb_image from "person" where "person"."C_ID"=:ls_c_id using sqlca; return lb_image //************************************************************** 有什么疑问可以咨询我: 昕晨 : EMAIL:jiangjeffrey@163.com 环境:PB65 数据库:sql anywhere 5.5 //数据库的字段根据自己的需要更改!!!!! //************************************************************* //***************************************************************************** 有人问到,如何清除数据库中的图片而不删除该条记录,操作如下: 保存图片到数据库要用UPDATEBLOB: UPDATEBLOB "M" SET "M"."PHOTO" = :ib_image WHERE "M"."C_ID" = :ls_c_id ; 只删除图片而不删除记录要用UPDATE: UPDATE "M" SET "M"."PHOTO" = null WHERE "M"."C_ID" = :ls_c_id ; (数据库字段根据自己的做更改!) 之前提供的gf_open_pic()函数说明: 由于PowerBuilder提供的fileread()函数每次只能读出字节小于32765的图片,当图片大于32765时,我提供的gf_open_pic()函数循环读图片,传入两个参数p_1(picture),lb_image(blob)
|