C 將檔案儲存到Oracle的BLOB欄位

2021-04-29 02:11:30 字數 2357 閱讀 7835

private void button1_click(object sender, eventargs e)

catch

oledbcommand cmd = new oledbcommand(cnnstr, con);

cmd.commandtype = commandtype.text;

cmd.commandtext = cnnstr;

string imgpath = @"c:/a.txt";//檔案所在路徑  

filestream file = new filestream(imgpath, filemode.open, fileaccess.read);

byte imgbyte = new byte[file.length];//把轉成 byte型 二進位製流  

file.read(imgbyte, 0, imgbyte.length);//把二進位製流讀入緩衝區  

file.close();

cmd.commandtext = " insert into test(id,zp ) values ('17',:zp) ";//正常sql語句插入資料庫  

cmd.parameters.add("zp", system.data.oledb.oledbtype.binary, imgbyte.length);

cmd.parameters[0].value = imgbyte;

trycatch (system.exception e1)

private void button2_click(object sender, eventargs e)

catch

oledbcommand cmd = new oledbcommand(cnnstr, con);

cmd.commandtype = commandtype.text;

cmd.commandtext = cnnstr;

string imgpath = @"c:/a.txt";//檔案所在路徑  

filestream file = new filestream(imgpath, filemode.open, fileaccess.read);

byte imgbyte = new byte[file.length];//把轉成 byte型 二進位製流  

file.read(imgbyte, 0, imgbyte.length);//把二進位製流讀入緩衝區  

file.close();

cmd.commandtext = " update test  set id='18',zp=:zp where id='17'";//正常sql語句插入資料庫  

cmd.parameters.add("zp", system.data.oledb.oledbtype.binary, imgbyte.length);

cmd.parameters[0].value = imgbyte;

trycatch (system.exception e1)

private void button3_click(object sender, eventargs e)

catch

datatable dt = new datatable();

system.data.oledb.oledbdataadapter da = new oledbdataadapter("select * from test",con);

da.fill(dt);

byte filebyte = (byte)(dt.rows[0]["zp"]);

filestream fsforwrite = new filestream(@"c:/test.txt", filemode.create);

fsforwrite.write(filebyte, 0, filebyte.getlength(0));

fsforwrite.close();

注意:連線oracle可以有多種形式的字串,

// hwqy_task.hwqy_orahelper.strconn = "provider=msdaora;pools=true;user id=" + linkuser + ";data source=" + linkname + ";password=" + linkpassword + ";";

hwqy_task.hwqy_orahelper.strconn = "provider=oraoledb.oracle;pools=true;user id=" + linkuser + ";data source=" + linkname + ";password=" + linkpassword + ";";

但用provider=msdaora的形式時,儲存到blob將出錯。只能採用provider=oraoledb.oracle的形式。

mysql將查詢結果儲存到檔案

1.新建查詢語句檔案query.sql,內容如下 set names utf8 select feedid,city message from feed limit 1000 上面的set names utf8語句是設施當前使用的編碼,如果編碼和資料庫的編碼不一致,會出現亂碼 2.執行如下 root...

Python OS模組 將檔案儲存到指定路徑

環境 python3.7 注意 windows下,用於區分系統路徑 在python裡面是轉義符 os.listdir 返回指定目錄下的所有目錄和檔名 os.mkdir 建立指定路徑下目錄 os.makedirs 建立多級目錄 os.chdir 改變當前路徑,到指定路徑 os.rename 重新命名目...

Unity將資料儲存到csv檔案中

遊戲中的資料持久化可以使用csv來儲存。csv是一種以逗號為分隔符的文字檔案,可以直接用excel開啟,或者轉換成excel,並且使用excel的操作。所以,在c 中可以使用流寫入,將需要寫入的資料用逗號拼接好。public void writecsv string strs,string path...