pb如何access数据库批量存储图片(长二进制格式)?
这段代码把图片已经批量存储到access数据库,但是存储的图片都是被选择的第一张图片。比如:我先择了10张图片,它存储的也是10张图片,但是都是第一个文件,2-10图片没有存储。
如何改进这段代码各位高手帮忙。
备注:被选择的图片名称和数据库ID一样
string ls_photofile
integer li_filenum,p_id,i
integer li_loops
integer li_counter
blob lb_picture
long ll_filelen
blob ll_read
Long ll_num
string ls_pathname, ls_filename[]
integer li_value
//1、选择图片
li_value = GetFileOpenName("选择照片", &
+ ls_pathname, ls_filename[], "图片文件","jpg File (*.jpg),*.jpg,bmp file(*.bmp),*.bmp,gif file(*.gif),*.gif")
IF li_value = 1 THEN
Elseif li_value=-1 then
MessageBox("选择照片","打开文件错误!")
End If
ll_num = upperbound(ls_filename)
for i=1 to ll_num
//2、获取图片的二进制数据
//处理照片文件数据开始
ls_photofile=ls_filename[i]
ll_filelen=filelength(ls_photofile)
li_filenum=fileopen(ls_photofile,streammode!,read!,lockread!)
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、存入数据库
p_id= integer(left(string(ls_filename[i]),len(string(ls_filename[i])) - 4))
updateblob 题库
set 图片=:lb_picture
where id =:p_id;
next
if sqlca.sqlcode<>0 then
messagebox("",sqlca.sqlerrtext)
//messagebox("系统提示","更新数据错误",stopsign!,ok!)
return;
else
messagebox("成功","更新数据成功")
end if