Using system;using system.collections.generic;using system.linq;using system.text;using System.Data.OleDb;using System.data;public class Accesshelper:idisposable {private OleDbConnection m_conn = new OleDbConnection (); public static string DATABASE = AppDomain.CurrentDomain.BaseDirectory + "rate.accdb"; Public Accesshelper () {string connstr = "Provider = microsoft.ace.oledb.12.0;"; ConnStr + = "Data Source =\" "+ DATABASE +" \ ""; M_conn. ConnectionString = ConnStr; M_conn. Open (); public void ExecuteCommand (String sql) {OleDbCommand cmd = null; Lock (Cmd=new OleDbCommand ()) {cmd. Connection = M_conn; Cmd.commandtext = SQL; Cmd. ExecuteNonQuery (); }} public void ExecuteCommand (String sql, oledbparameter[] PS) {OleDbCommand cmd = null; Lock (cmd = new Oledbcommand ()) {cmd. Connection = M_conn; Cmd.commandtext = SQL; foreach (OleDbParameter p in PS) {cmd. Parameters.Add (P); } cmd. ExecuteNonQuery (); }} public Object Querysome (String sql) {OleDbCommand cmd = null; Lock (cmd = new OleDbCommand ()) {cmd. Connection = M_conn; Cmd.commandtext = SQL; using (OleDbDataReader or = cmd. ExecuteReader ()) {if (or. Read ()) {return or. GetValue (0); }}} return null; } Public DataTable GetSource (string strsql) {DataTable dt = null; OleDbCommand cmd = null; OleDbDataAdapter ad = null; try {lock (dt = new DatatabLe ()) {cmd = new OleDbCommand (strSQL, m_conn); AD = new OleDbDataAdapter ((OleDbCommand) cmd); Dt. Clear (); Ad. Fill (DT); }} catch (Exception e) {throw e; } return DT; } void IDisposable.Dispose () {m_conn. Close (); M_conn. Dispose (); M_conn = null; } }
C # Accesshelper