Oracle Data Provider for. NET connection to oracle Database

Source: Internet
Author: User
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 () 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 ();
   

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.