当前位置:首页 » 文件管理 » 照片或者文件可以怎么装入数据库
扩展阅读
怎样用u盘启动光盘 2025-08-18 12:47:56
取卵后不出血可以运动 2025-08-18 12:39:35

照片或者文件可以怎么装入数据库

发布时间: 2025-06-22 09:22:50

Ⅰ pb中怎样把图像数据插入SQL表

一、可以存图片的相对地址到数据库中(如:\pic\A10020.jpg),显示的时候将列的display as picture属性勾选上。
这种方法显示的时候查询数据会快些。
二、将图片数据存入数据库中,如果存入数据库中,很快会让你的数据库增大,所以要尽量控制图片的大小,存和读取的方法在下面都有。
1、选择图片
string ls_pathname, ls_filename
integer li_value
li_value = GetFileOpenName("选择照片", &
+ ls_pathname, ls_filename, "图片文件","jpg File (*.jpg),*.jpg,bmp file(*.bmp),*.bmp,gif file(*.gif),*.gif")
IF li_value = 1 THEN
P_1.picturename=ls_pathname;
Elseif li_value=-1 then
MessageBox("选择照片","打开文件错误!")
End If
2、获取图片的二进制数据
//处理照片文件数据开始
string ls_photofile
integer li_filenum
integer li_loops
integer li_counter
blob lb_picture
long ll_filelen
blob ll_read
ls_photofile=p_1.picturename;
ll_filelen=filelength(ls_photofile)
li_filenum=fileopen(ls_photofile,streammode!,read!,lockread!)
//*fileread()函数不支持读取大于32k的文本,计算将使用fileread函数的次数 */
if ll_filelen>32765 then
li_loops=((ll_filelen - 1)/32765)+1
else
li_loops=1
end if
//读文件
for li_counter=1 to li_loops
fileread(li_filenum,ll_read)
lb_picture=lb_picture+ll_read
next
fileclose(li_filenum)
//显示图片
p_1.setpicture(lb_picture)
//处理照片文件结束

3、存入数据库
//存照片入数据库
updateblob t_teacher set pic=:lb_picture where code = :ls_code;
if sqlca.sqlcode<>0 then
messagebox("系统提示","更新数据错误",stopsign!,ok!)
return
end if
4、显示图片
blob lb_pic
string ls_code
ls_code="01007";
selectblob pic into :lb_pic from t_teacher where code=:ls_code;
if sqlca.sqlcode<>0 then
messagebox("系统提示","载入数据错误",stopsign!,ok!)
return
end if
setpicture(p_1,lb_pic)