asp.net OLE DB connection to an Access database _ Practical Tips

Source: Internet
Author: User

The use of OleDbCommand related action classes requires the introduction of SYSTEM.DATA.OLEDB namespaces.

Verify that the connection and command usage is correct by connecting to the Access database with a password and reading the data in it and placing it in the table.

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 connections, capturing of recordsets//Note change path String sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = E:/pro/web/access_test/app_dat A/northwind.mdb;
    Jet oledb:database password=111111 ";
    OleDbConnection myconnection = new OleDbConnection (sqlconn);
    Myconnection.open ();
    OleDbCommand mycommand = new OleDbCommand ("SELECT * from Shippers", myconnection);
    OleDbDataReader myreader;
   
    myreader = Mycommand.executereader ();
    Read Recordset 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 recordset and connect Myreader.close ();
  Myconnection.close (); }
}

The effect chart is as follows:

The full project file has been uploaded.

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.