C # Accesshelper

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.