Learning purpose: Learn to connect two databases
For ASP, our commonly used databases are nothing more than ACCESS and SQL SERVER, and the same is true for ASP.NET. However, ASP.NET has a special connection component for SQL SERVER and does not recommend OLE DB.
First, take a look at the ACCESS connection database and open it;
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
strConnection+=Server.MapPath("*.mdb"); //* is the name of the database
OleDbConnection objConnection=new OleDbConnection(strConnection);
objConnection.Open();
dim objConnection as OleDbConnection
objConnection=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("*.mdb"))
objConnection.Open()
Let’s take a look at the SQL SERVER connection database and open it;
string strConnection="server=database connection;uid=username;pwd=password;database=database name";
SqlConnediob objConnection=new SqlCOnnection(strConnection);
objConnection.Open();
dim objConnection as SqlConnectiom
objConnection=new SqlConnection("server=database connection;uid=username;pwd=password;database=database name")
objConnection.Open()
In fact, in most places, in addition to the connection statement, the difference between SQL SERVER and ACCESS is also the difference between SQL×× and OLEDB××.
In addition, if it is an ACCESS database, you need to include the following statement at the beginning of the ASPX file
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.OleDb"%>
If it is SQL SERVER, you need to include the following statements:
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
That’s all for today, and we’ll start talking about database reading tomorrow.