Common ADO Operation Access database

Source: Internet
Author: User
Tags access database

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;//usingSystem.Data.OleDb;//usingSystem.Drawing;//namespaceecolor{classControldbs {//defining a link string        PrivateOleDbConnection con; /// <summary>        ///constructor Function/// </summary>        /// <param name= "path" >Database Path</param>         PublicControldbs (stringpath) {Con=NewOleDbConnection (@"Provider=Microsoft.Jet.OLEDB.4.0;Data source="+path); }        /// <summary>        ///get SQL query data to data table/// </summary>        /// <param name= "SQL" >SQL statements</param>        /// <returns>Data Sheet</returns>         PublicDataTable getdatatable (stringSQL) {OleDbDataAdapter ADP=NewOleDbDataAdapter (SQL, con); Try{con.                Open (); DataTable DT=NewDataTable (); Adp.                Fill (DT); returnDT; }            Catch            {                return NULL; }            finally{con.            Close (); }        }        /// <summary>        ///get data to data set/// </summary>        /// <param name= "SQL" >SQL statements</param>        /// <returns>Data Set</returns>         PublicDataSet GetDataSet (stringSQL) {OleDbDataAdapter ADP=NewOleDbDataAdapter (SQL, con); Try{con.                Open (); DataSet DS=NewDataSet (); Adp.                Fill (DS); returnds; }            Catch            {                return NULL; }            finally{con.            Close (); }        }        /// <summary>        ///get data to DataReader/// </summary>        /// <param name= "SQL" >SQL statements</param>        /// <returns>DataReader</returns>         PublicOleDbDataReader Getdatareader (stringSQL) {OleDbCommand cmd=NewOleDbCommand (SQL, con); Try{con.                Open (); OleDbDataReader Dr=cmd.                ExecuteReader (); returnDr; }            Catch            {                return NULL; }        }        /// <summary>        ///returns the first column of the first row of the SQL query/// </summary>        /// <param name= "SQL" >SQL statements</param>        /// <returns>string of first column in first row</returns>         Public stringGetfirstvalue (stringSQL) {OleDbCommand cmd=NewOleDbCommand (SQL, con); Try{con.                Open (); stringStrchar =cmd. ExecuteScalar ().                ToString (); returnStrchar; }            Catch            {                return NULL; }            finally{con.            Close (); }        }        /// <summary>        ///Execute SQL statement/// </summary>        /// <param name= "SQL" >SQL statements</param>         Public voidRunsqlcmd (stringSQL) {OleDbCommand cmd=NewOleDbCommand (SQL, con); Try{con.                Open (); Cmd.            ExecuteNonQuery (); }            Catch            { }            finally{con.            Close (); }        }    }}

Common ADO Operation Access database

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.