C # connect to the Oracle database and display the code of the database table

Source: Internet
Author: User
Tags oracleconnection

Add reference:

Using System. Data. OracleClient;

Here I select an Oracle (Service name (Data Source here is separated from Data Source): GIS user Name (user): gis password (password): gis) your Oracle database has its own name. Please modify it.

I have selected a table named "Pipeline", where "MSFS, BH" are all columns in the table.

Code:

Add a button.

Private void button#click (object sender, EventArgs e)

{

String connection = "Data Source = GIS; user = gis; password = gis"; // password of the Data Source connecting to the database

OracleConnection coon = new OracleConnection (connection); // create a database connection

OracleCommand cmd = new OracleCommand ("select MSFS, BH from Pipeline", coon); // execute data connection. to select all columns, you can set MSFS, change BH to *, that is, "select * from Pipeline"

 

DataSet ds1;

 

Ds1 = new DataSet (); // defines a DataSet

 

OracleDataAdapter da1 = new OracleDataAdapter (cmd); // retrieves a data table

Da1.Fill (ds1); // load data to a data set

 

DataTable dt = ds1.Tables [0]; // put data into the table

 

Coon. Close (); // Close the database connection

 

/// Traverse

//// If the table is empty, return

// The following code can be used to operate a table. if you want to directly display the table, you can directly add the data display code. The if else code below does not need to be used.

If (dt = null)

{

Return;

}

Else

{

For (int I = 0; I <dt. Rows. Count; I ++)

{

}

}

// Display data in the dataGridView

This. Maid = dt. DefaultView;

This. Maid ();

}

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.