ADO. Net,

Source: Internet
Author: User
Tags oracleconnection

ADO. Net,

ADO. NET is a database access architecture in the. NET Framework. ADO is short for ActiveX Data Objects. It is used to access the database by. NET applications.

The six objects of ADO. NET are:

1. Connection (connect to the database and use this object for transaction processing)

2. Command (execute T-SQL statements-database commands that return data, modify data, run stored procedures, and send or retrieve parameter information)

3. DataAdapter (the main function is to fill in DataSet and notify the database to update data to the database after the data in the Dataset object is modified)

4. DataReader (read database, read-only mode, only forward)

5. DataSet (the core concept of DataSet-ADO. Net, which can be regarded as a database in memory)

6. DataTable (can be understood as a data table in memory)

 

ConnectionThere are four types of classes:SqlConnection,OleDbConnection,OdbcConnectionAndOracleConnection.

Objects in the SqlConnection class are connected to the SQL Server database. Objects in the OracleConnection class are connected to the Oracle database (this method is used for Oracle versions earlier than 11. ODP is used for versions earlier than 11. net); OleDbConnection Class Object connection supports ole db databases, such as Access; while OdbcConnection class objects connect to any databases that support ODBC (Open Database interconnection.

All communication with the database is ultimately completed through the Connection object.

SqlConnectionConnectionString)

Add namespace: using System. Data. SqlClient;

Connect to the Database: string conString = "data source = IP address; Database = Database name; user id = user name; password = password ";

ExecuteNonQuery (): executes the SQL statement and returns an integer variable. If the SQL statement operates on database records, the number of records affected by the operation is returned, if SQL = "CREATE TABLE LookupCodes (code_id smallint IDENTITY () PRIMARY KEY CLUSTERED, code_desc varchar (50) NOT NULL)", return-1 after the TABLE is created successfully.

ExecuteScalar (): executes the SQL statement (if the SQL statement is a query Select statement) to return the first column of the first row of the query result. If (if the SQL statement is not a query Select statement) then, the returned result cannot be ToString () or Equals (null) because the objects are not listed. That is to say, the returned results have no effect.

The ExecuteReader method executes the SQL statement (if the SQL statement is a Select query) and returns a set of query results. The type is System. Data. OleDb. OleDbDataReader. You can use this result to obtain the queried Data. If (If SQL is not a query Select), a set of System. Data. OleDb. OleDbDataReader types (EOF) without any Data is returned)

OleDbConnectionDifferent data sources are connected. The connection strings vary depending on different data sources.

Add namespace: using System. Data. OleDb;

Connect to SQL Server: string conString = "Provider = SQLOLEDB.1; Persist Security Info = False; user id = user name; Database = Database name; data source = COMPUTER ;";

OleDbConnection myconnection = new OleDbConnection (conString );

Myconnection. open ();

Connection Access: string conString = "Provider = Microsoft. Jet. OLEDB.4.0; data source = C: \ Database1.mdb; Persist Security Info = False ;";

OleDbConnection myconnection = new OleDbConnection (conString );

Myconnection. open ();

(You can also create a. udl file to obtain the string)

Connect to Oracle:

String conString = "Provider = MSDAORA; user id = user name; password = password; data source = db; Persist Security Info = False ;";

String oradb = "Provider = OraOLEDB. Oracle; Data Source = water; User Id = modem; Password = modem ;";

OleDbConnection myconnection = new OleDbConnection (conString );

Myconnection. open ();

In OleDb mode, Microsoft and Oracle provide their own OleDb drivers, with few differences in usage.

Reference Class Library: Microsoft only needs System. data. dll; if you use the Oracle driver, you only need to introduce the System. data. dll, but the premise is that the first installation of Oracle.. Net data access component.
Connection string: provider -- Microsoft "provider = MSDAORA;"; Oracle-"provider = 'oraoledb. oracle ';". The former is not used much; the latter needs to install the Oracle client;

Error Handling for "OraOLEDB. Oracle" provider solution not registered on the local computer:

Regsvr32 E: \ app \ Administrator \ product \ 11.2.0 \ dbhome_1 \ oledb \ lib \ OraOLEDB11.dll

OracleConnectionConnecting to Oracle --- no longer maintained by Microsoft. We recommend that you use Oracle's ODP. Net connection

Join the namespace: using System. Data. OracleClient;

Connect to the Database: string conString = "data source = IP address; Database = Database name; user id = user name; password = password ";

OracleConnection myconnection = new OracleConnection (conString );

Myconnection. open ();

 Note:To use different Connection objects, you must import different namespaces. The namespace of OleDbConnection is System. Data. OleDb. The namespace of SqlConnection is System. Data. SqlClient. The namespace of OracleConnection is System. Data. OracleClinet.

 

DBHelpers is a simple but powerful library used to access components using simple ADO. NET databases.

 

What features does DBHelpers contain?

Async (asynchronous), Batch execution (Batch execution script), Custom converters (Custom type conversion ),

Multi table retrieval (Multi-result set query), Easy safe parameterized DbCommand (simple and secure parameterization ),

Automatic mapping of objects (Automatic ing type), Built in paging support (built-in support for paging), and so on.

DBHelpers built-in method

ExecuteNonQuery、ExecuteReader、ExecuteScalar、

ExecuteDataTable、ExecuteDataSet、ExecuteArray、ExecuteDictionary、ExecuteObject、ExecuteList、

ExecuteNonQueryAsync、ExecuteObjectAsync、ExecuteListAsync

Github:

https://github.com/nvivo/dbhelpers

 

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.