大家好這是我做的往資料庫里存圖片的程式,編譯沒錯誤,可總是顯示不出來圖片,應該是沒存進,不知道哪點錯了,請各位指出啊
integer tu_file,tu_ret,loops,i
string wai_file,wai_path,usernum
blob tu_xiao,tu_da
long tu_len,du_bytes
if trim(sle_1.text)="" and trim(sle_2.text)="" then
messagebox("提示","請輸入其中一個圖片的編號")
return
end if
if trim(sle_1.text)<>"" or trim(sle_2.text)<>"" then
tu_ret=getfileopenname("選擇圖片檔案",wai_path,wai_file,"jpg","jpg檔案(*.jpg),*.jpg")
if tu_ret=1 then
setnull(tu_xiao)
setpointer(hourglass!)
tu_len=filelength(wai_file)
tu_file=fileopen(wai_file,streammode!,read!,lockread!)
if tu_len>32765 then
if mod(tu_len,32765)=0 then
loops=tu_len/32765
else
loops=tu_len/32765 + 1
end if
for i=1 to loops
du_bytes=fileread(tu_file,tu_xiao)
if i=1 then
tu_da=tu_xiao
else
tu_da=tu_da + tu_xiao
end if
next
fileclose(tu_file)
end if
end if
end if
if sle_1.text<>"" then
usernum=trim(sle_1.text)
updateblob curiosity
set cpic=:tu_da
where cnum=:usernum;
else
usernum=trim(sle_2.text)
updateblob managrment
set mpic=:tu_da
where mum=:usernum;
commit using sqlca;
end if
if sqlca.sqlcode=0 then
messagebox("提示","圖片成功入庫!")
else
messagebox("提示","圖片入庫失敗!")
end if
uj5u.com熱心網友回復:
debug后得到tu_xiao=null說明根本沒讀到資料,這是怎么回事啊,各位uj5u.com熱心網友回復:
你判斷檔案大小讀取資料時有問題查看下幫助 file open 看例子中是如何讀取 大于32,765 bytes的資料的。
uj5u.com熱心網友回復:
用這個方法來讀圖片吧,這樣速度快也不會有問題http://blog.csdn.net/yyoinge/article/details/6935768
uj5u.com熱心網友回復:
經多次debug后已完全確定是fileread()的問題,其他方面完全正確,就是一到fileread就讀不到任何資料,fileopen打開正確,判斷長度等地方都正確,到底是怎么回事啊?幫幫我吧,各位高手。uj5u.com熱心網友回復:
你fileread代碼寫到判斷位元組長度多少的回圈中了。。。
// 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_FileNum, b)
tot_b = tot_b + b
NEXT
uj5u.com熱心網友回復:
用這段試試integer tu_file,tu_ret,loops,i
string wai_file,wai_path,usernum
blob tu_xiao,tu_da
long tu_len,du_bytes
if trim(sle_1.text)="" and trim(sle_2.text)="" then
messagebox("提示","請輸入其中一個圖片的編號")
return
end if
if trim(sle_1.text)<>"" or trim(sle_2.text)<>"" then
tu_ret=getfileopenname("選擇圖片檔案",wai_path,wai_file,"jpg","jpg檔案(*.jpg),*.jpg")
if tu_ret=1 then
setnull(tu_xiao)
setpointer(hourglass!)
tu_len=filelength(wai_file)
tu_file=fileopen(wai_file,streammode!,read!,lockread!)
if tu_len>32765 then
if mod(tu_len,32765)=0 then
loops=tu_len/32765
else
loops=tu_len/32765 + 1
end if
else
loops=1
end if
for i=1 to loops
du_bytes=fileread(tu_file,tu_xiao)
tu_da=tu_da + tu_xiao
next
fileclose(tu_file)
if sle_1.text<>"" then
usernum=trim(sle_1.text)
updateblob curiosity
set cpic=:tu_da
where cnum=:usernum;
else
usernum=trim(sle_2.text)
updateblob managrment
set mpic=:tu_da
where mum=:usernum;
commit using sqlca;
end if
if sqlca.sqlcode=0 then
messagebox("提示","圖片成功入庫!")
else
messagebox("提示","圖片入庫失敗!")
end if
uj5u.com熱心網友回復:
濤哥,你那代碼少寫了兩個end if啊,還是不行啊,大家再幫我想想辦法哈,我在做課程設計馬上就要交了,我太想把這個問題解決了,給我老師發代碼老師說代碼沒問題,可就是存不進圖片啊uj5u.com熱心網友回復:
大家多出出主意啊,是不是pb自身出問題了啊uj5u.com熱心網友回復:
沒注意到你選擇圖片那里的判斷,你可以在代碼最后加上2個END IF。
integer tu_file,tu_ret,loops,i
string wai_file,wai_path,usernum
blob tu_xiao,tu_da
long tu_len,du_bytes
if trim(sle_1.text)="" and trim(sle_2.text)="" then
messagebox("提示","請輸入其中一個圖片的編號")
return
end if
if trim(sle_1.text)<>"" or trim(sle_2.text)<>"" then
tu_ret=getfileopenname("選擇圖片檔案",wai_path,wai_file,"jpg","jpg檔案(*.jpg),*.jpg")
if tu_ret=1 then
setnull(tu_xiao)
setpointer(hourglass!)
tu_len=filelength(wai_file)
tu_file=fileopen(wai_file,streammode!,read!,lockread!)
if tu_len>32765 then
if mod(tu_len,32765)=0 then
loops=tu_len/32765
else
loops=tu_len/32765 + 1
end if
else
loops=1
end if
for i=1 to loops
du_bytes=fileread(tu_file,tu_xiao)
tu_da=tu_da + tu_xiao
next
fileclose(tu_file)
if sle_1.text<>"" then
usernum=trim(sle_1.text)
updateblob curiosity
set cpic=:tu_da
where cnum=:usernum;
else
usernum=trim(sle_2.text)
updateblob managrment
set mpic=:tu_da
where mum=:usernum;
commit using sqlca;
end if
if sqlca.sqlcode=0 then
messagebox("提示","圖片成功入庫!")
else
messagebox("提示","圖片入庫失敗!")
end if
end if
end if
uj5u.com熱心網友回復:
濤哥,又試了一遍,還是不行啊,你再想想可能是什么其他原因,應該不是代碼的原因,或者再讓其他高手幫我想想哈,我太想把這個問題解決了。我的課程設計就這個還有點技術含量。uj5u.com熱心網友回復:
貌似你說得對了,loops不管檔案有多大總是1
uj5u.com熱心網友回復:
如果使用高版本的PB,有個FileReadEx,不需要判斷檔案大小,可以一次全讀進來。uj5u.com熱心網友回復:
string ls_photofileinteger li_filenum
integer li_loops
integer li_counter,ll_wpdmcount
long ll_filelen
blob lb_read
blob lb_picture
ls_photofile = sle_photo.text //照片檔案
// 獲 取 文 件 的 大 小
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, lb_read )
lb_picture = lb_picture + lb_read
NEXT
FileClose(li_filenum)
debugbreak()
//顯示圖片
p_1.SetPicture(lb_picture)
//寫入資料庫
UPDATEBLOB aaa
SET pic = :lb_picture
WHERE ;
IF Sqlca.SQLNRows > 0 THEN
COMMIT;
Messagebox('提示資訊','記錄保存成功!')
Else
Rollback;
Messagebox('提示資訊','記錄保存成功,照片檔案保存失敗!' + sqlca.sqlerrtext)
END IF
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/71879.html
標籤:數據庫相關
上一篇:PB12.5連接資料庫
