Method for connecting ASP. NET oledb to Access database, oledbaccess

Source: Internet
Author: User

Method for connecting ASP. NET oledb to Access database, oledbaccess

To use the OleDBCommand operation class, you must introduce the System. Data. OleDb namespace.

Connect to an access database with a password to read the data and place the data in the table to verify the correctness of the connection and command usage.

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using System. data. oleDb; public partial class _ Default: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {// database connection, acquisition of record set // change the path String sqlconn = "Provider = Microsoft. jet. OLEDB.4.0; Data Source = E:/pro/web/access_test/app_data/Northwind. mdb; Jet OLEDB: Database Password = 111111 "; OleDbConnection myConnection = new OleDbConnection (sqlconn); myConnection. open (); OleDbCommand myCommand = new OleDbCommand ("select * from forwarder", myConnection); OleDbDataReader myReader; myReader = myCommand. executeReader (); // read the record set Response. write ("<table border = 1 cellspacing = 0 cellpadding = 2>"); Response. write ("<tr bgcolor = # DAB4B4>"); for (int I = 0; I <myReader. fieldCount; I ++) Response. write ("<td>" + myReader. getName (I) + "</td>"); Response. write ("</tr>"); while (myReader. read () {Response. write ("<tr>"); for (int I = 0; I <myReader. fieldCount; I ++) Response. write ("<td>" + myReader [I]. toString () + "</td>"); Response. write ("</tr>");} Response. write ("</table>"); // close the record set and connect to myReader. close (); myConnection. close ();}}

As follows:

The complete project file has been uploaded.

Related Article

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.