NET Operations Access database sample sharing

Source: Internet
Author: User
Tags tostring access database

  This article mainly describes the net operations Access database sample, the need for friends can refer to the following

  Code as follows: using System; Using System.Data; Using System.Configuration; Using System.Linq; Using System.Web; Using System.Web.Security; Using System.Web.UI; Using System.Web.UI.HtmlControls; Using System.Web.UI.WebControls; Using System.Web.UI.WebControls.WebParts; Using System.Xml.Linq; Using System.Data.OleDb;  ///<summary>///accessdb Summary description///</summary> public class Accessdb {    public accessdb ()     {       //todo: Here Add constructor logic    }      ///<summary> & nbsp  ///Read Access database    ///</summary>     private void Readaccessdata ()     {&nbs P      //1, establishing connection         String saccessconnection = @ "Provider=microsoft.jet.oledb.4.0;d ATA source=c:documents and settingsadministrator.www-410adc78208 desktop applications. mdb ";         OleDbConnection odcconnection = new OleDbConnection (saccessconnection);   &NBSP    //2, open connection         Odcconnection.open ();        //Set up SQL query         OleDbCommand Odcommand = Odcconnection.createcommand ();        //3, input query statement         Odcommand.commandtext = "Select table. number, table. [123], table. [456] from [table]; ";        //Set up read         OleDbDataReader odrreader = Odcommand.executereader ();        //query and display data         while (Odrreader.read ())         {& nbsp           ListViewItem item = new ListViewItem ();             item. SubItems.Add (Odrreader[0]. ToString ());             item. SubItems.Add (Odrreader[1]. ToString ());             item. SubItems.Add (Odrreader[2]. ToString ());             THIS.LISTVIEW1.ITEMS.ADD (item);        }        /close connection         odrreader.close ();         odcconnection.close ();    }    ///<summary>    ///add    ///</summary>    / <param name= "Sender" ></param>    ///<param name= "E" ></param>     private void Button1_Click (object sender, EventArgs e)     {       //1, establishing connection         String saccessconnection = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:documents and settingsadministrator.www-410adc78208 desktop applications. mdb ";         OleDbConnection odcconnection = new OleDbConnection (saccessconnection);        //2, open connection         Odcconnection.open ();        //Set up SQL query         OleDbCommand Odcommand = Odcconnection.createcommand ();     &nbsp  //3, input query statement         Odcommand.commandtext = INSERT into [table] ([123],[456]) VALUES (' 88 ', ' 88 ') ";        //execute         odcommand.executenonquery ();        //close connection         odcconnection.close ();         this.listView1.Items.Clear ();         readaccessdata ();    }      ///<summary>    ///Delete    ///</summary> &nbsp ;  ///<param name= "sender" ></param>    ///<param name= "E" ></param>     private void Button3_Click (object sender, EventArgs e)     {       //1, establishing connection         String saccessconnection = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:documents and settingsadministrator.www-410adc78208 desktop applications. mdb ";         OleDbConnection odcconnection = new OleDbConnection (saccessconnection);        //2, open connection         Odcconnection.open ();        //Set up SQL query         OleDbCommand Odcommand = Odcconnection.createcommand ();        //3, input query statement         String sql = "DELETE table." Number from [table] WHERE ((tab Le. Number) = "+ this.listview1.selecteditems[0]." SUBITEMS[1]. Text + ")";         odcommand.commandtext = SQL;        //execute         odcommand.executenonquery ();        //close connection         odcconnection.close ();         this.listView1.Items.Clear ();         readaccessdata ();    }      ///<summary>    ///update    ///</summary> &nbsp ;  ///<param name= "sender" ></param>    ///<param name= "E" ></param>     private void button2_click (object sender, EventArgs e)     {       //1, establishing a connection         String saccessconnection = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:documents and Se ttingsadministrator.www-410adc78208 desktop applications. mdb ";         OleDbConnection odcconnection = new OleDbConnection (saccessconnection);        //2, open connection         Odcconnection.open ();        //Set up SQL query         OleDbCommand Odcommand = Odcconnection.createcommand ();        //3, input query statement         String sql = "UPDATE [table] SET 123= '", 456= ' one ' &nbs P WHERE ((table. Number) = "+ this.listview1.selecteditems[0]. SUBITEMS[1]. Text + ")";         odcommand.commandtext = SQL;        //execute         odcommand.executenonquery ();        //close connection        Odcconnection.close ();         this.listView1.Items.Clear ();         readaccessdata ();    }}  

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.