|
一、首先要写好两个函数,分别是文件的读取与写入:
参考 pb中读写文件的函数:http://blog.csdn.net/xys_777/archive/2010/08/04/5787833.aspx
二、保存文件
li_value = GetFileOpenName("选择文件",ls_docname,ls_named)IF li_value = 1 THENif f_readfile(lb_fj,ls_docname)=1 then ll_picid=gf_getid('T_Picture') //这是一个得到新增id的函数//需要先插入这条数据的其他信息INSERT INTO T_Svt_Picture ( PictureId,PicName,detaillogId ) VALUES ( :ll_picid,:ls_named, :ld_detaillogId);if sqlca.sqlcode<0 thenrollback;messagebox('系统提示','数据保存失败')returnend if//再用updateblob更新blob字段updateblob T_Picture set PicBlob=:lb_fj where pictureid=:ll_picid;if sqlca.sqlcode<0 thenrollback;messagebox('系统提示','保存失败')returnelsecommit;end if end ifend if
三、打开文件
//用selectblob将blob类型数据赋值给blob变量 lb_fjselectblob PicBlob into :lb_fj from T_Picture where pictureid=:ll_picid;if sqlca.sqlcode<>0 thenmessagebox('系统提示','资料读取失败')returnend if//需要将文件重新在磁盘里保存出来,需要在之前存数据库是记录文件名 dw_1.object.picnamels_docname='c:/worktemp'if not DirectoryExists(ls_docname) then CreateDirectory(ls_docname)ls_docname=ls_docname+dw_1.object.picname[row]if f_writefile(lb_fj,ls_docname)=1 then//调用api打开文件if ShellExecuteA(Handle(parent),ls_null,ls_docname,ls_null,ls_null, 1) > 32 thenreturnelse messagebox('系统提示','系统打开文件出错')returnend ifend if//api定义Function long ShellExecuteA (ulong hwnd, string lpOperation, string lpFile,string lpParameters, string lpDirectory, long nShowCmd) library "shell32.dll" |
|