ASP. NET database connection method

Source: Internet
Author: User

ASP. NET database connection method

What is ADO. NET?
ADO. NET is an integral part. NET Framework
ADO. NET is a group of classes used to process data access.
ADO. NET is completely XML-based
ADO. NET is also different. With ADO, there is no Recordset object

Create a database connection
We will use the example of the Northwind database.

First, import the "System. Data. OleDb" namespace. We need to name this with Microsoft Access and other ole db database vendors. We will create a connection to the database in the Page_Load subroutine. We create a dbconn variable as a new OleDbConnection class connection string to identify the database of the ole db provider and location. Then, we open the database connection:

<% @ Import Namespace = "System. Data. OleDb" %>
<Script runat = "server">
Sub Page_Load
Dim dbconn
Dbconn = New OleDbConnection ("Provider = Microsoft. Jet. OLEDB.4.0;
Data source = "& server. mappath (" northwind. mdb "))
Dbconn. Open ()
End sub
</Script>
Note: The connection string must be a continuous string with no broken lines! Create a database command to specify the records to be retrieved from the database. We will create a dbcomm variable as a new OleDbCommand class. This OleDbCommand class issues SQL query database tables: <% @ Import Namespace = "System. Data. OleDb" %> <script runat = "server">
Sub Page_Load
Dim dbconn, SQL, dbcomm
Dbconn = New OleDbConnection ("Provider = Microsoft. Jet. OLEDB.4.0;
Data source = "& server. mappath (" northwind. mdb "))
Dbconn. Open ()
SQL = "SELECT * FROM MERs"
Dbcomm = New OleDbCommand (SQL, dbconn)
End sub
</Script> Create a DataReader. The OleDbDataReader class is used to read stream records from a data source. A DataReader is the OleDbCommand object for creating the call ExecuteReader method: <% @ Import Namespace = "System. Data. OleDb" %> <script runat = "server">
Sub Page_Load
Dim dbconn, SQL, dbcomm, dbread
Dbconn = New OleDbConnection ("Provider = Microsoft. Jet. OLEDB.4.0;
Data source = "& server. mappath (" northwind. mdb "))
Dbconn. Open ()
SQL = "SELECT * FROM MERs"
Dbcomm = New OleDbCommand (SQL, dbconn)
Dbread = dbcomm. ExecuteReader ()
End sub
</Script>

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.