1. Current ADO.NET current ADO.NET provides two hosting providers: a use of SQL Server 7.0 or higher, another OLE DB provider for all other you may have already installed. In both cases you use different classes, but follow similar naming rules. In addition to the prefix, the name is the same. The preceding case is SQL, and the latter case is ADO. <% @ Import Namespace = "System.data.ado"%> <% @ import namespace = "system.data.sql"%> You should use SQL classes to access SQL Server tables because they directly enter the internal API of the database server, Skip the intermediate layer represented by the OLE DB provider. The ADO class is the .NET interface on the OLE DB provider, which works using the COM InteroP bridge. 2. Connecting a database Dim myConnection As New SQLConnection ( "server = localhost; uid = sa; pwd =; database = pubs") Dim myCommand As New SQLDataSetCommand ( "select * from Authors", myConnection) or SQLConnection myConnection = new SQLConnection (); myConnection.DataSource = "localhost"; myConnection.UserID = "sa"; myConnection.Password = ""; myConnection.ConnectionTimeout = 30; myConnection.Open (); myConnection.Database = "pub"; myConnection.IsolationLevel = IsolationLevel.ReadCommitted Here we need to tell the method and attributes of the connection. ConnectionTIMEOUT Timeout Database Default Database Datasource DNS UserId It turns out that the UID Password State gets the state of the current connection open () Open Close () Off 3.
The operation database passes a Command object, we can operate DIM MyConnection as SqlConnection = New SqlConnection ("Server = localhost; uid = sa; pwd =; database = pubs") DIM MyCommand as sqlcommand = new sqlcommand ("SELECT * from Authors ", myConnection) myConnection.Open () Dim dr As New SQLDataReader myCommand.Execute (dr) ... myConnection.Close () or do so Dim myConnection As New SQLConnection (" server = localhost; uid = sa; pwd = Database = PUBS ") Dim MyCommand As New SqlCommand (_" Update Authors Set Phone = '(800) 555-5555' Where au_id = '123-45-6789' ", _ myConnection) MyCommand.activeConnection.Open () MyCommand .ExecutenonQuery () myCommand.activeConnection.close () These are SQLCommand standard usage, which lists all properties and related methods of Command. ActiveConnection to acquire or set up links Connections CommandText execute SQL statements or stored procedures (StoredProcedure) name CommandTimeout CommandType Command timeout type of operation (StoredProcedure, Text, TableDirect) are three default Text Execute operation using the stored procedure Parameters () or execute SQL statements Subsequent, but there is no return, or the number of records is returned, or the number of records is noted. When you run, you must pay attention to closing the Connection, otherwise the server resources will be consumed. 4.
The display of data before the explanation of this section, let's create a database first, named the ASPNet and there is a table User structure as follows: Uid Username Email 1 User1 Mail1 2 User2 Mail2 3 User3 Mail3 SQL Statement Select * from User Database Screen SELECT * FROM User Database Screen LocalHost; UID = SA; PWD =; DATABASE = ASPNET 4.1 Display data with DataReader method There are two ways to display data DataReader method, and DataSet method, and DataReader can only store query data, let us first use the DataReader method to display