C#串連Oracle資料庫查詢資料

來源:互聯網
上載者:User

標籤:

C#串連Oracle資料庫可以實現許多我們需要的功能,下面介紹的是C#串連Oracle資料庫查詢資料的方法,如果您對C#串連Oracle資料庫方面感興趣的話,不妨一看。

using System;  using System.Collections.Generic;  using System.ComponentModel  using System.Data.OracleClient;;//這行和下一行都要先在引用中填加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 從region到endregion是手工寫的。別的都是系統自動產生的              string constring = "data source=wzd;user=wzd;password=wzd;";//定義串連資料庫的字串              OracleConnection conn = new OracleConnection(constring);//進行串連              try              {                  conn.Open();//開啟指定的串連                  OracleCommand com = conn.CreateCommand();                  com.CommandText = "select name from mytable where card_no=‘0000000002‘";//寫好想執行的Sql語句                  OracleDataReader odr = com.ExecuteReader();                  while (odr.Read())//讀取資料,如果返回為false的話,就說明到記錄集的尾部了                   {                      this.lbl.Text = odr.GetOracleString(0).ToString();//將讀取到的值顯示到定義的控制項中。                  }                  odr.Close();//關閉reader.這是一定要寫的              }              catch              {                  MessageBox.Show("erro");//如果發生異常,則提示出錯              }              finally              {                  conn.Close();//關閉開啟的串連              }               #endregion          }      }  }  

  

C#串連Oracle資料庫查詢資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.