Visual Studio 2013 connects to Oracle 11g and gets data: (ii: Implementation)

Source: Internet
Author: User
Tags oracleconnection

1. Create a new WinForm form in VS

(1) a button

(2) A Data table view (the data table displayed inside)

2. Double-click the button to enter the code

(1) adding using System.Data.OracleClient;

If you are not prompted to find Oracle, the Toolbox is not available by default, toolbox--right--Select items--. NET Framework Components

I've added all the Oracle fields to the Toolbox,

(2) Automatically eject the "Data Adapter Configuration Wizard" is to configure the properties of your database connection,

The last one doesn't know what it means, I wrote a SELECT statement just like the SQL statement in the button event code

And then the following,

Solution Explorer--Programs--references--with System.Data.OracleClient,

See Using System.Data.OracleClient; I don't have an error.

Alternatively: Right-click on the reference, add Reference, add System.Data.OracleClient

(3) button event code

 Private voidButton1_Click (Objectsender, EventArgs e) {            stringconnectionString; stringqueryString; ConnectionString="Data SOURCE=ORCL; User Id=scott; Password=tiger"; QueryString="SELECT * from TEST"; OracleConnection myconnection=NewOracleConnection (connectionString); OracleCommand mycommand=Myconnection.createcommand (); myCommand.CommandText=queryString;            Myconnection.open (); OracleDataAdapter Orada=NewOracleDataAdapter (mycommand); DataSet DS=NewDataSet ();            Orada.fill (DS);            Myconnection.close (); DataTable Dtbl=ds. tables[0];  This. Datagridview1.datasource =dtbl; }

(4) operation, the results are as follows:

As with the data in my database

Visual Studio 2013 connects to Oracle 11g and gets data: (ii: Implementation)

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.