1、從資料庫讀取blob資料寫入本地檔案
// strid 主鍵欄位名 strzp **欄位名 strtb 資料庫表名 strpath 存放**的本地路徑
2、將本地檔案存入資料庫
//引數說明:資料庫表名,主鍵欄位名,**欄位名,寫入主鍵值,本地**檔名,含完整路徑
private boolean insertpic(string d_tb, string d_id, string d_zp, string id, string filename)
int result = 0;
string strsql = "insert into " + d_tb + "(" + d_id + "," + d_zp + ") values('" + id + "', :pic)";
oraclecommand cmd = new oraclecommand();
cmd.connection = conn;
cmd.commandtext = strsql;
filestream fs = system.io.file.openread(filename);
byte imagebyte = new byte[fs.length];
fs.read(imagebyte, 0, (int)fs.length);
cmd.parameters.add(new oracleparameter(":pic", imagebyte));
tryresult = cmd.executenonquery();
catch
if (result == 1)
return true;
else
return false;
2、用c#實現mysql資料庫blob欄位的讀取
讀資料:
public list getlist(string typeauthorization)
string selectall = 「需要執行的sql語句」
list authorizationinfolist = null;
using (mysqldatareader reader = dal.mysqlhelper.executereader(commandtype.text, selectall))
if (reader != null)
authorizationinfolist = new list();
while (reader.read())
authorizationinfo info = new authorizationinfo();
info.id = reader.getint32(0);
info.instrumentid = reader.isdbnull(1) ? 0 : reader.getint32(1);
//此處省略其他字段……..
info.machineid_crypt = reader.isdbnull(17) ? null : (byte)reader.getvalue(17);
authorizationinfolist.add(info);
return authorizationinfolist;
寫資料:
public int add(authorizationinfo authorizationinfo, string type)
string sqlstr = 「執行的sql語句」;
mysqlparameter mysqlparameters =
new mysqlparameter("@machineid_crypt",mysqldbtype.blob),
mysqlparameters[10].value = authorizationinfo.machineid_crypt;
object obj = dal.mysqlhelper.executescalar(dal.mysqlhelper.conn, commandtype.text, sqlstr, mysqlparameters);
if (obj == null)
return 0;
else
return convert.toint32(obj);
資料庫連線,讀取
連線sql server sqlconnection myconnection new sqlconnection persist security info false integrated security sspi database dream server local myconnectio...
ado讀取資料庫
當我們在使用ado運算元據庫的時候經常會碰到一些問題!例如資料庫為空我們就應該對是否為空做出判斷!variant t var var bstr t m precordset getcollect z controllersn if var.vt vt null else m list.setitem...
pandas read sql 讀取資料庫
1.連線sqlalchemy pandas.read sql 可以在資料庫中執行指定的sql語句查詢,以dataframe 的型別返回查詢結果。import sqlalchemy import pandas as pd 建立資料庫連線,這裡使用的是pymysql engine sqlalchemy....