C # connecting Oracle database query data

Source: Internet
Author: User
Tags oracleconnection

C # connecting Oracle databases can implement many of the features we need, and here's how C # connects Oracle database query data, and if you're interested in C # connecting to Oracle database, you might want to take a look at this.

Using System;  Using System.Collections.Generic; Using System.ComponentModel using system.data.oracleclient;;/  /This line and next line must first fill in the reference to add system.data.oracleclient using System.Data;  Using System.Drawing;  Using System.Text;   Using System.Windows.Forms;              namespace WindowsApplication1 {public partial class Form1:form {public Form1 () {          InitializeComponent (); private void Button1_Click (object sender, EventArgs e) {#region from region to Endreg Ion is written by hand. Everything else is automatically generated by the system string constring = "Data source=wzd;user=wzd;password=wzd;";                  /define a string to connect to the database OracleConnection conn = new OracleConnection (constring);//Make connection try { Conn. Open ();//Opens the specified connection oraclecommand COM = conn.                  CreateCommand (); Com. CommandText = "SELECT name from MyTable where card_no= ' 0000000002 '";//write good SQL statement to execute OracleDataReader ODR = Com. ExecutereadER (); while (ODR. Read ())//reads the data and, if returned to false, indicates to the end of the recordset {This.lbl.Text = ODR. Getoraclestring (0).                  ToString ();//The value read to is displayed in the defined control. } ODR. Close ();//Turn reader off. This is a must-write} catch {MessageBox.Show ("Erro");//If the hair Error} finally {Conn.   Close ();//Closes Open connection} #endregion}}}

  

C # connecting Oracle database query data

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.