. NET and Oracle access, after all, is not a mother-in-law, and sqlserver is a little different.
1. namespace selection:
Access the Oracle database through the system. Data. oracleclient, system. Data. oledb, and system. Data. ODBC namespaces. System. Data. oracleclient has the highest access efficiency. system. Data. oracleclient also has the most support for Oracle types. After all, it is customized for Oracle.
2. database connection:
Whether it is the kind of machine that needs to run in. Net (ASP. NET is the Web server) to access Oracle, install the Oracle client component. (This is different from the two types of MS databases, MS things install MDAC: Microsoft Data Access Component 2.6 or later, there is no need to install the SQL Server Client or office software, .)
The connection string used to access the Oracle database in system. Data. oracleclient is: "User ID = username; Password = password; Data Source = server ".
In system. Data. oledb, the connection string used to access the Oracle database is: "provider = msdaora.1; user id = user name; Password = password; Data Source = server ".
The connection string used to access the Oracle database in system. Data. ODBC is: "driver = Microsoft ODBC for Oracle; uid = username; Pwd = password; server = server ";
3. Data Types in Oracle:
Most of the data types of SQL Server are easy to find close to. net, while the types in Oracle are much different from those in. net.
Number: Number type. Generally, it is number (m, n), M is a valid number, and N is the number of digits after the decimal point (0 by default). This is in decimal format.
Nvarchar2: variable-length Unicode (UNICODE). (The nvarchar2 type is added to orcle8i. Later, Oracle will only support nvarchar2.) (remove "N" from non-Unicode, the same below .)
Nchar: Unicode ).
Nclob: The field used to store a large number of characters (UNICODE.
Date: date type.
In Oracle, fields cannot be of the BIT or bool type. They are generally replaced by number (1.
4. Connection sample:
Connect with oracleclient. (for other connections, you only need to change the namespace and connection string)
String oracle_conn = "User ID = userid; Password = ******; Data Source = servername ";
String SQL _search = "select * From table_test ";
Using (oracleconnection conn = new oracleconnection (oracle_conn ))
{
Conn. open ();
Oraclecommand COM = new oraclecommand (SQL _search, Conn );
Oracledatareader DR = com. executereader ();
While (dr. Read ())
{
Response. Write (Dr ["c_name"]. tostring () + "<br> ");
}
Dr. Close ();
Conn. Close ();