Oracle data provider for. net connection to Oracle Database (02)

Source: Internet
Author: User
Tags oracleconnection

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 ();
}
}

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.