C # and Oracle database

Source: Internet
Author: User

I. Connecting an Oracle Database

    1. Install the client: The Oracle database is built on the remote server, the local only needs to install a client, and then under the installation directory (D:\app\fangs\product\12.1.0\client_3\Network\Admin, not necessarily the D disk) Configure Tnsnames.ora to refer to the contents of the sample folder in the same directory. is to specify the connection name, remote Ip,servicename/sid. You can then use the SQL Develper tool to open the database and view all the contents of the database.
    2. C # programs through the ADO connection: first create the connection string: string connstr = "DATA source=***; password=***; USER id=** ", as well as subsequent ADO operations, can connect to the database.
    3. Get Data: Reference MSDN MSDN ADO

      I. Establishing a database connection, Conn.Open ()

      II. Create DataAdapter, which is the connection between the database and the DataSet object

      III. Declare and create a DataSet object instance before you can begin loading the data, which may contain several separate tables

      Iv. DataAdapter provides fill, with the FillSchema method.

      The FillSchema method loads some data table information, column names, constraints, and so on.

      A separate DataTable object within the Tables collection in the V. DataSet to provide data

      VI. Datatables.row can access each row

Data types in two C # correspond to Oracle database field types

Refer to this article

It is particularly important to note that the type of number (10,1) in the Oracle database can be used in decimal


Three. sql

One needs to be passed in SQL, so here is the syntax for the SQL string.

    1. string [email protected] "";: @:c# Special String declaration method, called "verbatim string" (verbatim strings), using this symbol will tell the compiler this is a verbatim string, which itself is often used to write the path of the specified file or directory, Because it notifies the compiler to "\" as a literal constant instead of an escape character. It is used here because the SQL statement can be long, and he supports wrapping a string
    2. arguments to sql:string sql = @ "nsert into A Values (: Id_num): Indicates that this is a variable, which is how the Oracle database is expressed. Other databases use a different marking method, such as SQL Server using @. Note that the parameter name here does not make the Oracle database keyword, otherwise it will be an error, indicating that the parameter name is invalid.
    3. SQL statement Plus constant: eg. Where a>2, defines 2 as a variable count in class constants. Can be written in where a> ' "+ constants.count + @" ' must pay attention to the space, otherwise may not identify the keyword
NOTE: When writing SQL statements in C #, SQL statements are executed in SQL developer, ensuring that the SQL syntax is not error-free and then written to the program. As mentioned in the ":" tag, SQL developer can be checked out




C # and Oracle database

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.