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>