Some time ago, this article was put on hold due to lack of Internet access. We will take the noon time to fix it today.
Oracle data provider for. Net has two namespaces: Oracle. dataaccess. Client and Oracle. dataaccess. types. Oracle. dataaccess. Client is used to set database connections and other general functions. Oracle. dataaccess. types is used to set Custom Data Types in Oracle. Before using the SDK, you must add oracle. dataaccesss. dll references to the project. The following is an example:
1. Create a database
Create a table named oracletypestable
"Create table oracletypestable (myvarchar2 varchar2 (3000), mynumber Number (28, 4) primary key, mydate date, myraw raw (255 ))";
Insert a row of data
"Insert into oracletypestable values ('test', 4, to_date ('2017-01-11
12:54:01 ', 'yyyy-mm-dd hh24: MI: ss'), '123 ')";
2. C # instance
Private void page_load (Object sender, system. eventargs E)
{
String connstring = "User ID = user name; Password = password; Data Source = Data Source ";
// Instantiate the oracleconnection object
Oracleconnection conn = new oracleconnection (connstring );
Try
{
Conn. open ();
// Instantiate the oraclecommand object
Oraclecommand cmd = conn. createcommand ();
Cmd. commandtext = "select * from data source. oracletypestable ";
Oracledatareader oracledatareader1 = cmd. executereader ();
// Read data
While (oracledatareader1.read ())
{
// Read and display the data in the first column of the First row
Oraclestring oraclestring1 = oracledatareader1.getoraclestring (0 );
Response. Write ("<br> oraclestring:" + oraclestring1.tostring ());
// Read and display the data in the second column of the First row
Oracledecimal oraclenumber1 = oracledatareader1.getoracledecimal (1); //. getoraclevalue (1); // getoraclenumber (1 );
Response. Write ("<br> oraclenumber:" + oraclenumber1.tostring ());
Response. Write ("<br> numbertype:" + oraclenumber1.gettype ());
// Read and display the data in the third column of the first row
Oracledate oracledatetime1 = oracledatareader1.getoracledate (2 );
Response. Write ("<br> oracledatetime:" + oracledatetime1.tostring ());
// Read and display the data in the fourth column of the first row
Oraclebinary oraclebinary1 = oracledatareader1.getoraclebinary (3 );
If (oraclebinary1.isnull = false)
{
Foreach (byte B in oraclebinary1.value)
{
Response. Write ("<br> byte:" + B. tostring ());
}
}
}
// Release resources
Oracledatareader1.close ();
}
Catch (exception ee)
{
// Exception Handling
Strmess. Text = ee. message;
}
Finally
{
// Close the connection
Conn. Close ();
}
}