ASP.net database connection method

Source: Internet
Author: User

ASP.net database connection method

Ado. NET is what?
Ado. NET is an integral part. NET Framework
Ado. NET is used by a group of classes to handle data access
Ado. NET is completely xml-based
Ado. NET is also different, using ADO, no Recordset objects

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

First, the import of the "System.Data.OleDb" namespace. We need this to be named 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 identifying the OLE DB provider and location of the database. 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 constant string without breaking the line! Create a database command to specify the retrieved records from the database, we will create a Dbcomm variable as a new OleDbCommand class. The OleDbCommand class is the issuing SQL query database table: <%@ 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 Customers"
Dbcomm=new OleDbCommand (Sql,dbconn)
End Sub
</script> Create a DataReader the OleDbDataReader class is used to read streams of records from a data source. A DataReader is a OleDbCommand object that establishes 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 Customers"
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.