PB訪問image檔案,txt檔案例項

2021-08-29 20:25:32 字數 3755 閱讀 8019

具體步驟:

資料庫建表

use [server]

go/****** object:  table [dbo].[img_test]    script date: 10/25/2018 16:20:57 ******/

set ansi_nulls on

goset quoted_identifier on

goset ansi_padding on

gocreate table [dbo].[img_test](

[id] [int] identity(1,1) not null,

[img_text] [varchar](256) null,

[picture] [image] null,

primary key clustered 

([id] asc

)with (pad_index  = off, statistics_norecompute  = off, ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  = on) on [primary]

) on [primary] textimage_on [primary]

goset ansi_padding off

go

視窗:w_test

open事件

dw_1.settransobject(sqlca)

dw_1.retrieve()

函式: wf_display_image

入參:long al_id

blob emg_pic

long ll_id

int li_id

selectblob     picture

into         :emg_pic

from         img_test

where     id = :al_id;

if sqlca.sqlcode = 0 then

else

messagebox("","抽取,資料庫連線錯誤,"+sqlca.sqlerrtext)

return

end if 

if isnull(emg_pic ) or len(emg_pic) = 0 then

else

p_1.setpicture(emg_pic)

end if

dw: dw_1

retrieveend事件

long ll

if rowcount > 0 then

this.scrolltorow(1)

ll = this.object.id[1]

wf_display_image(ll)

end if

clicked事件

long ll

if row > 0 then

ll = this.object.id[row]

wf_display_image(ll)

end if

pb訪問檔案函式用法參考:

新增功能

按鈕:cb_1

clicked事件

/*

1.選擇檔案

插入其他欄位到表內,獲取id

2.讀取檔案    獲取二進位制資料

獲取檔案長度,判斷需要多少次迴圈讀取

獲取檔案控制代碼

迴圈讀取檔案二進位制資料

3.顯示

4.更新二進位制資料到表內

string ls_filename ,ls_pathname

int li_return ,li_num

long ll_id ,ll_len ,ll_loops ,ll_count

blob lb_read ,lb_pic

cb_1.enabled = false

//獲取檔案路徑、檔名稱

li_return = getfileopenname("選擇**" ,ls_pathname ,ls_filename ,&

"檔案" ,"jpg file (*.jpg),*.jpg,bmp file(*.bmp),*.bmp,gif file(*.gif),*.gif")

if li_return = 1 then

else

messagebox("","新增,操作取消或讀取出錯")

goto endw

end if

//插入檔名到表

insert into img_test(img_text) 

values(:ls_filename)

using sqlca;

if sqlca.sqlcode = 0 then

else

messagebox("","新增,插入資料失敗")

goto endw

end if

commit using sqlca;

//獲取id

select max(id)

into :ll_id

from img_test

using sqlca;

//判斷檔案長度

ll_len = filelength(ls_filename)

if ll_len > 1 then

else

return

end if

ll_loops = ((ll_len - 1)/32765) + 1        //int型別小數部分捨去

//獲取控制代碼     fileopen(filename}}}})

li_num = fileopen(ls_filename ,streammode! ,read! ,lockread!)

//迴圈取資料

for ll_count = 1 to ll_loops

fileread(li_num ,lb_read)        //讀取資料到blob

lb_pic = lb_pic + lb_read

next

//關閉檔案系統

fileclose(li_num)

//顯示

p_1.setpicture(lb_pic)

//存入資料庫

sqlca.autocommit = true

updateblob img_test

set picture = :lb_pic

where id = :ll_id

using sqlca;

if sqlca.sqlcode = 0 then

else

messagebox("","更新,更新資料庫出錯")

end if 

sqlca.autocommit = false

disconnect using sqlca;

connect using sqlca;

​​​​​​​

goto endw

endw:

cb_1.enabled = true

dw_1.settransobject(sqlca)

dw_1.retrieve()

return 

參考

python將excel檔案變成txt檔案

import xlrd def row2str row data values for i in range len row data if i len row data 1 values values str row data i else values values str row data i...

9 6 檔案 檔案的隨機訪問

在c 中可以由程式控制檔案指標的移動,從而實現檔案的隨機訪問,即可讀寫流中任意一段內容。一般文字檔案很難準確定位,所以隨機訪問多用於二進位制檔案。如 例9.9 中物件中兩個字串是按實際串長存放的,不是按陣列元素來存放的,而 例9.10 中是按陣列長度來存放的,每個物件資料長度固定,所以便於隨機訪問。...

moto E2檔案訪問

折騰了幾天終於在moto e2手機上的檔案訪問成功了,我在j2me中訪問手機目錄 目錄字首file 也可以用 file localhost 主目錄 手機目錄 phone 所以moto機器的檔案目錄為file phone 或者file localhost phone 儲存卡目錄為file sd mot...