自己寫的資料庫鏈結類,請高手指點一下。

2021-04-18 18:45:45 字數 3208 閱讀 9598

using system;

using system.collections.generic;

using system.text;

using system.data;

using system.data.oledb;

namespace databaseconn

set}

private oledbconnection connection;

/// /// 資料庫鏈結

///

public oledbconnection conn

set}

private oledbcommand command;

/// /// 資料庫命令執行者

///

public oledbcommand command

set}

private oledbdataadapter dateadapter;

private oledbdatareader datereader;

/// /// 資料庫讀取器

///

public oledbdatareader datereader

set}

private string sql;

/// /// 執行sql

///

public string sql

set}

private string error_info;

/// /// 錯誤資訊

///

public string errorinfo

set}

/// /// 初始化鏈結

///

public connection()

/// /// 初始化鏈結

///

/// 資料庫鏈結字串

public connection(string connectionstring)

/// /// 取得datatable

///

/// 返回datatable

public datatable getdatatable()

command.commandtype = commandtype.text;

command.commandtext = sql;

dateadapter = new oledbdataadapter();

dateadapter.selectcommand = command;

dateadapter.fill(temp);

//清理oledbcommand.parameters變數。

if (command.parameters.count > 0)

}catch (exception e)

return temp;

}/// /// 取得dataset

///

/// 返回dataset

public dataset getdataset()

command.commandtype = commandtype.text;

command.commandtext = sql;

dateadapter = new oledbdataadapter();

dateadapter.selectcommand = command;

dateadapter.fill(temp);

//清理oledbcommand.parameters變數。

if (command.parameters.count > 0)

}catch (exception e)

return temp;

}/// /// 執行sql命令

///

/// 返回影響行數

public int executesql()

command.commandtype = commandtype.text;

command.commandtext = sql;

command.connection = connection;

temp = command.executenonquery();

//清理oledbcommand.parameters變數。

if (command.parameters.count > 0)

}catch (exception e)

return temp;

}/// /// 取得第一列第一行

///

/// 返回第一列第一行

public object executescalar()

command.commandtype = commandtype.text;

command.commandtext = sql;

command.connection = connection;

temp = command.executescalar();

//清理oledbcommand.parameters變數。

if (command.parameters.count > 0)

}catch (exception e)

return temp;

}/// /// 取得讀取器

///

/// 返回讀取器

public object getdatareader()

command.commandtype = commandtype.text;

command.commandtext = sql;

command.connection = connection;

temp = command.executereader();

//清理oledbcommand.parameters變數。

if (command.parameters.count > 0)

}catch (exception e)

return temp;

}/// /// 關閉釋放所有資源鏈結

///

public void dispose()

if (datereader != null)

datereader.dispose();

}if (connection != null)

connection.dispose();

}if (command != null)}}

}

自己寫的通過ADO操作mysql資料庫

include include include import c program files common files system ado msado15.dll no namespace rename eof adoeof rename bof adobof class adoconn virt...

仿Petshop寫的資料庫操作類

using system using system.componentmodel using system.collections using system.diagnostics using system.data using system.data.sqlclient using system....

自己封裝的MSSQL的資料庫操作類

using system using system.data using system.data.sqlclient using system.web.configuration namespace niunan.tg029.hr.utility 建立command物件 預設是sql語句 sql語句...