c 操作access資料庫image ole欄位

2022-03-15 00:27:45 字數 4418 閱讀 4725

using system;

using system.data;

using system.configuration;

using system.web;

using system.data.oledb;

using system.collections;

/// /// accehelper 的摘要說明

///

public static class accesshelper

}catch (exception ex)

}/// /// 用現有的資料庫連線執行乙個sql命令(不返回資料集)

///

/// ///舉例:

/// int result = executenonquery(connstring, "publishorders", new oledbparameter("@prodid", 24));

///

/// 乙個現有的資料庫連線

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 執行命令所影響的行數

public static int executenonquery(oledbconnection connection, string cmdtext, params oledbparameter commandparameters)

/// ///使用現有的sql事務執行乙個sql命令(不返回資料集)

///

/// ///舉例:

/// int result = executenonquery(trans, "publishorders", new oledbparameter("@prodid", 24));

///

/// 乙個現有的事務

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 執行命令所影響的行數

public static int executenonquery(oledbtransaction trans, string cmdtext, params oledbparameter commandparameters)

/// /// 用執行的資料庫連線執行乙個返回資料集的sql命令

///

/// /// 舉例:

/// oledbdatareader r = executereader(connstring, "publishorders", new oledbparameter("@prodid", 24));

///

/// 乙個有效的連線字串

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 包含結果的讀取器

public static oledbdatareader executereader(string connectionstring, string cmdtext, params oledbparameter commandparameters)

catch

}/// /// 返回乙個dataset資料集

///

/// 乙個有效的連線字串

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 包含結果的資料集

public static dataset executedataset(string connectionstring, string cmdtext, params oledbparameter commandparameters)

catch}}

/// /// 用指定的資料庫連線字串執行乙個命令並返回乙個資料集的第一列

///

/// ///例如:

/// object obj = executescalar(connstring, "publishorders", new oledbparameter("@prodid", 24));

///

///乙個有效的連線字串

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 用 convert.to把型別轉換為想要的

public static object executescalar(string connectionstring, string cmdtext, params oledbparameter commandparameters)

}/// /// 用指定的資料庫連線執行乙個命令並返回乙個資料集的第一列

///

/// /// 例如:

/// object obj = executescalar(connstring, "publishorders", new oledbparameter("@prodid", 24));

///

/// 乙個存在的資料庫連線

/// 儲存過程名稱或者sql命令語句

/// 執行命令所用引數的集合

/// 用 convert.to把型別轉換為想要的

public static object executescalar(oledbconnection connection, string cmdtext, params oledbparameter commandparameters)

/// /// 將引數集合新增到快取

///

/// 新增到快取的變數

/// 乙個將要新增到快取的sql引數集合

public static void cacheparameters(string cachekey, params oledbparameter commandparameters)

/// /// 找回快取引數集合

///

/// 用於找回引數的關鍵字

/// 快取的引數集合

public static oledbparameter getcachedparameters(string cachekey)

/// /// 準備執行乙個命令

///

/// sql命令

/// sql連線

/// sql事務

/// 命令文字,例如:select * from products

/// 執行命令的引數

private static void preparecommand(oledbcommand cmd, oledbconnection conn, oledbtransaction trans, string cmdtext, oledbparameter cmdparms)

}}

用法舉例

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.windows.forms;

using system.data.oledb;

using system.io;

namespace windowsformstest

/// ///

///

/// byte

public static image buffertoimage(byte buffer)

byte data = null;

image oimage = null;

bitmap obitmap = null;

//建立副本

data = (byte)buffer.clone();

trycatch

return obitmap;

}/// /// 將轉換為byte

///

///

///

public static byte imagetobuffer(image image, system.drawing.imaging.imageformat imageformat)

byte data = null;

using (memorystream omemorystream = new memorystream())

}return data;

}private void button1_click(object sender, eventargs e)

private void button2_click(object sender, eventargs e)

private void button2_click_1(object sender, eventargs e)

}}

C 操作Access資料庫

using system using system.collections.generic using system.linq using system.text using system.data using system.data.oledb using system.configuration...

c 操作ACCESS資料庫

c 簡單操作access資料庫 這兩天做專案,需要將資料存到資料庫,並進行一些簡單的增刪改操作,剛好記錄下access資料庫的基本操作方法,下文中提及到知識應用如有不正確的地方,大家多多指正,在程式開始時,我打算使用一些資料庫操作語句來建立乙個資料庫,不過好像用的不是很成功。而且如果要手動建立資料庫...

c 操作Access資料庫

先新增兩個com引用 第乙個 microsoft activex data objects 2.8 library 第二個 microsoft ado ext.2.8 for ddl and security 1.建立access資料庫 using adox adox.catalog cat new...