The fifth day of the 10 day society asp.net

Source: Internet
Author: User
Tags access database
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 OleDbConnection
Objconnection=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" +Server.MapPath ("*.mdb"))
Objconnection.open ()

Next look at the SQL Server connection database and open;

String strconnection= "server= database connection; uid= user name; 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, 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.


Related Article

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.