C # connect Oracle code through oledb

Source: Internet
Author: User
Tags oracleconnection

First install the Oracle client 1. Choose Control Panel> Administrative Tools> data source (ODBC)> add data source> select Oracle client data source name, we recommend that you use the same description as Sid to describe TNS service name. The tnsnames in the environment variable tns_admin directory is automatically displayed in the drop-down menu. name of SERVICE_NAME in the ora file, that is, the SID userid username to connect 2. Code string connectionstring = "Data Source = orcl; user id = Scott; Password = Scott "; // connection string oracleconnection conn = new oracleconnection (connectionstring); // create a new connection try {Conn. open (); // open the connection oraclecommand cmd = Conn. createcommand (); cmd. commandtext = "select * from EMP"; // SQL statement oracledatareader rs = cmd. executereader (); While (RS. read () // read data if RS. if the returned value of read () is false, {MessageBox. show (RS. getstring (1);} Rs. close ();} catch (exception e) {MessageBox. show (E. message);} finally {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.