C #. net4.0 use odac to connect to Oracle

Source: Internet
Author: User
Tags oracleconnection

1. Install odac (I installed xcopy);: http://www.oracle.com/technetwork/developer-tools/visual-studio/downloads/index.html

2. A 4.0-based application is started in vs2010.

3. WriteCode:

 

String Strconn = " Data Source = (description = (address = (Protocol = TCP) (host = 10.10.190.91) (Port = 1521) (CONNECT_DATA = (SID = orcl ))); user ID = rockuser; Password = rockuser; " ; // This can also be placed in Web. config, And the firewall should open 1521 ports.

String SQL =   " Select * From org_userinfo " ;
Dataset DS =   New Dataset ();
Using (ODC. oracleconnection myconn =   New ODC. oracleconnection (strconn ))
{
Myconn. open ();
Using (ODC. oracledataadapter myda =   New ODC. oracledataadapter (SQL, myconn ))
{
Myda. Fill (DS );
}
}
Gridview1.datasource = DS. Tables [ 0 ]. Defaultview;
Gridview1.databind ();

 

4. Remember to add oracle. dataaccess reference!

My oracle. dataaccess is in the C: \ oracle \ odp.net \ bin \ 4 path.

 

5. Remember to add oracle. dataaccess on the page!

Using ODC = oracle. dataaccess. client;

 

Sample Code: http://files.cnblogs.com/ewyb/OracleClient.zip

 

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.