ASP.net learning Purpose: Learn to connect two kinds of databases
For ASPs, the database we use is nothing more than access and SQL Server, but for ASP.net, ASP.net has a special connection component for SQL Server and does not recommend Ole DB.
First look at Access's 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 Sqlconnectiom
Objconnection=new SqlConnection ("server= database connection; uid= username; pwd= password; database= database name")
Objconnection.open ()
In fact, in most places, the difference between SQL Server and access is the difference between SQLXX and oledbxx except for the connection statement.
Also, if you are an Access database, you need to include the following statements at the beginning of the ASPX file:
<% @Import namespace= "System.Data"%>
<% @Import namespace= "System.Data.OleDb"%>
If you are SQL Server, you need to include the following statement:
<% @Import namespace= "System.Data"%>
<% @Import namespace= "System.Data.SqlClient"%>
That's it for today. Read about the database tomorrow.
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.