pb中往資料庫里添加照片,是直接像添加別的資料一樣,還是得在應用程式里寫代碼添加啊?各位高手
uj5u.com熱心網友回復:
先將圖片讀入blob中,再保存 blob資料,和其它資料的保存不一樣uj5u.com熱心網友回復:
使用這里的函式讀取圖片檔案到blob型別的變數(假設為lb)中http://blog.csdn.net/yyoinge/article/details/6935768
然后使用updateblob語法提交到資料庫
updateblob t_表名 set 圖片欄位 = :lb where 某列 = :某值 using sqlca;
uj5u.com熱心網友回復:
就是這樣處理的。
uj5u.com熱心網友回復:
把下面這段代碼用記事本保存為text檔案然后把檔案名改成 gf_read_graphfile.srf
匯入到pb中
global type gf_read_graphfile from function_object
end type
forward prototypes
global function blob gf_read_graphfile (string as_filename)
end prototypes
global function blob gf_read_graphfile (string as_filename);Blob lbb_read,lbb_total
Integer li_fileptr,li_loops,i
Long ll_filelen,ll_bytes_read
ll_filelen = FileLength(as_filename) //獲取檔案長度, 必須在打開之前
li_fileptr = FileOpen(as_filename,STREAMMODE!,Read!,LOCKREAD!)
IF li_fileptr = -1 THEN
MessageBox('提示!',"圖形檔案打開錯誤!")
RETURN lbb_total
END IF
IF ll_filelen > 32765 THEN //一次只能讀32K
IF Mod(ll_filelen, 32765) = 0 THEN
li_loops = ll_filelen / 32765
ELSE
li_loops = (ll_filelen / 32765) + 1
END IF
ELSE
li_loops = 1
END IF
//回圈讀取圖片檔案
FOR i = 1 TO li_loops
ll_bytes_read = FileRead(li_fileptr,lbb_read)
ll_filelen = Len(lbb_read)
lbb_total = lbb_total + lbb_read
NEXT
FileClose(li_fileptr)
RETURN lbb_total
end function
使用這個函式
Bolb lblb_graph
String ls_graphfile
sqlca.AutoCommit = TRUE
ls_graphfile = "C:\text.bmp"
lblb_graph = gf_read_graphfile(ls_graphfile)
update 表名 set 欄位名=:lblb_graph where 條件;
IF sqlca.sqlcode = 0 THEN
COMMIT;
ELSE
ROLLBACK;
END IF
欄位型別一定要是那種支持bolb型別的欄位
比如SQL server的image欄位型別
uj5u.com熱心網友回復:
這個函式是用來把資料庫里的bolb值轉換成圖片檔案的把下面這段代碼用記事本保存為text檔案
然后把檔案名改成 gf_blobtofile.srf
匯入到pb中
global type gf_blobtofile from function_object
end type
forward prototypes
global subroutine gf_blobtofile (blob pb_blob, string ps_file)
end prototypes
global subroutine gf_blobtofile (blob pb_blob, string ps_file);//--------------------------------------------------------------------
// 引數:
// value blob pb_blob 資料庫的存的blob型別的圖片
// value string ps_file 圖片的路徑 如c:\test.bmp
//--------------------------------------------------------------------
// 回傳: (none)
//--------------------------------------------------------------------
// 作者: WLshi
//--------------------------------------------------------------------
// Copyright (c) 2002-2006 DATAWINDOW(TM), All rights reserved.
//--------------------------------------------------------------------
// 修改歷史:
//
//====================================================================
Blob zpbuff
UInt sub,n,j,fh1
String ext,file2
Long ll,bytes_read,new_pos,Len
file2 = ps_file
FileDelete(file2)
fh1 = FileOpen(file2, StreamMode!,Write!,SHARED!,Append!)
ll = Len(pb_blob)
n = 0
IF ll > 32766 THEN
IF Mod(ll,32766) = 0 THEN
n = ll/32766
ELSE
n = (ll/32766)+1
END IF
ELSE
n = 1
END IF
new_pos = 1
FOR j = 1 TO n
zpbuff = BlobMid(pb_blob,new_pos,32765)
bytes_read = FileWrite(fh1,zpbuff)
new_pos = new_pos+32765
NEXT
FileClose(fh1)
end subroutine
函式的使用方法
Bolb lblb_graph
String ls_graphfile
ls_graphfile = "c:\aaa.bmp"
selectblob 欄位名 into :lblb_graph from 表名 where 條件;
gf_blobtofile(lblb_graph,ls_graphfile)
就這樣可以了
希望可以幫到LZ
uj5u.com熱心網友回復:
謝謝各位,我先試試哈uj5u.com熱心網友回復:
求在pb中存盤照片的具體步驟,急用,謝謝轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/71857.html
標籤:數據庫相關
上一篇:pb菜鳥求助
下一篇:關于連鎖總部同分部資料交換的問題
