C #Compose Database Operation Class

xiaoxiao2021-03-06  146

Class code: using system; using system.data.oledb; Namespace dbclass {////

/// db_class's summary description.

/// public class Db_Class {public OleDbConnection Conn; // Constructors public Db_Class () {Conn = new OleDbConnection ( "Provider = SQLOLEDB; Server = (local); Pwd = 123456; UID = sa; Database = Test ");} // Open the data source link Public OLIDBCONNECTION DB_CONN () {conn.open (); return conn;} // Returns the DataReader dataset, the following SQL can dynamically generate public OLEDBDATAREADER DB_CREATEREADER (String SQL) {db_conn ); OleDbCommand cmd = new OleDbCommand (SQL, Conn); OleDbDataReader Rs = cmd.ExecuteReader (); return Rs; this.close ();} // return the DataReader data set, the following SQL procedure is stored public OleDbDataReader Db_CommandReader (string SQL) {Db_Conn (); OleDbCommand cmd = new OleDbCommand (SQL, Conn); cmd.CommandType = CommandType.StoredProcedure; OleDbDataReader Rs = cmd.ExecuteReader (); return Rs; this.close ();} // return the DataSet Data set public oledbdataset db_created, {db_conn (); OLEDBCommand cmd = new oledbcommand (SQL, conn); OLEDBDataAdapter Adpt = New OLEDBDataAdapter (cmd, conn); DataSet DS = New dataset (); adpt.fill (DS, "newTable"); return ds; this.close ();} // Return to data DataReader dataset, do not need to return data modification, delete You can use this function PUBLIC BOOL DB_EXECUTENONQUERY ( String sql) {db_conn (); OLEDBCOMMAND CMD = New OLEDBCOMMAND (SQL, CONN); try {oledbdatareader = cmd.executenonquery (); return true;} catch {return false;} this.close ();} // Close Data Link Public Void Close () {Conn.close ();}}} Usage: use system; use system.collections; use system.ComponentModel; use system.data; useing system.drawing; using system.Web; using System.Web.SessionState; Using System.Web.ui;

转载请注明原文地址:https://www.9cbs.com/read-127388.html

New Post(0)