自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#連接Oracle數(shù)據(jù)庫(kù)字符串

開發(fā) 后端
C#連接Oracle數(shù)據(jù)庫(kù)以及C#連接Oracle數(shù)據(jù)庫(kù)字符串等內(nèi)容將在本文中展現(xiàn),希望本文能對(duì)大家了解C#連接數(shù)據(jù)庫(kù)有所幫助。

C#連接Oracle數(shù)據(jù)庫(kù)字符串(查詢數(shù)據(jù))

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel  
  4. using System.Data.OracleClient;;//這行和下一行都要先在引用中填加system.data.oracleclient  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.  
  10. namespace WindowsApplication1  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.           
  19.         private void button1_Click(object sender, EventArgs e)  
  20.         {  
  21.             #region 從region到endregion是手工寫的。別的都是系統(tǒng)自動(dòng)生成的  
  22.             string constring = "data source=wzd;user=wzd;password=wzd;";//定義連接數(shù)據(jù)庫(kù)的字符串  
  23.             OracleConnection conn = new OracleConnection(constring);//進(jìn)行連接  
  24.             try 
  25.             {  
  26.                 conn.Open();//打開指定的連接  
  27.                 OracleCommand com = conn.CreateCommand();  
  28.                 com.CommandText = "select name from mytable where card_no='0000000002'";//寫好想執(zhí)行的Sql語(yǔ)句  
  29.                 OracleDataReader odr = com.ExecuteReader();  
  30.                 while (odr.Read())//讀取數(shù)據(jù),如果返回為false的話,就說明到記錄集的尾部了  
  31.  
  32.                 {  
  33.                     this.lbl.Text = odr.GetOracleString(0).ToString();//將讀取到的值顯示到定義的控件中。  
  34.                 }  
  35.                 odr.Close();//關(guān)閉reader.這是一定要寫的  
  36.             }  
  37.             catch 
  38.             {  
  39.                 MessageBox.Show("erro");//如果發(fā)生異常,則提示出錯(cuò)  
  40.             }  
  41.             finally 
  42.             {  
  43.                 conn.Close();//關(guān)閉打開的連接  
  44.             }  
  45.  
  46.             #endregion  
  47.         }  
  48.     }  

C#連接Oracle數(shù)據(jù)庫(kù)字符串的代碼

注意:一定要添加這個(gè):

項(xiàng)目->添加引用->.NET->System.Data.OracleClient.dll

  1. using System;  
  2. using System.Data;  
  3. using System.Windows.Forms;  
  4. using System.Data.OracleClient;  
  5.  
  6. namespace Test  
  7. ...{  
  8.     /**//**//**////   
  9.     /// 簡(jiǎn)潔期間,直接將實(shí)現(xiàn)寫在構(gòu)造函數(shù)中  
  10.     ///   
  11.     public class Test  
  12.     ...{  
  13.         public Test()  
  14.         ...{  
  15.             //  
  16.             // TODO: 在此處添加構(gòu)造函數(shù)邏輯  
  17.             //  
  18.  
  19.             string ConnectionString = "Data Source=LiPu; User Id=SCOTT; Password=scott";  
  20.  
  21. //C#連接Oracle數(shù)據(jù)庫(kù)字符串,Data Source 是指數(shù)據(jù)庫(kù)名字.如我用的是本機(jī)的Oracle 的數(shù)據(jù)庫(kù),名字為L(zhǎng)iPu. user id 是  
  22.  
  23. //用戶名,你可以用System 或是你自己添加的一個(gè)用戶.Password是對(duì)應(yīng)用戶的密碼.  
  24.  
  25.  
  26.              OracleConnection conn = new OracleConnection(ConnectionString);    //創(chuàng)建一個(gè)新連接  
  27.               
  28.             try  
  29.            {  
  30.                  conn.Open();    //打開連接  
  31.                  OracleCommand cmd = conn.CreateCommand();  
  32.  
  33.                  cmd.CommandText = "select * from emp";    //SQL語(yǔ)句  
  34.                  OracleDataReader rs = cmd.ExecuteReader();  
  35.  
  36.                 while (rs.Read())    //讀取數(shù)據(jù),如果rs.Read()返回為false的話,就說明到記錄集的尾部了  
  37.        {  
  38.                      MessageBox.Show(rs.GetString(1));  
  39.                  }  
  40.  
  41.                  rs.Close();  
  42.              }  
  43.  
  44.             catch (Exception e)  
  45.             ...{  
  46.                  MessageBox.Show(e.Message);  
  47.              }  
  48.             finally  
  49.             ...{  
  50.                  conn.Close();  
  51.              }  
  52.          }  
  53.      }  

C#連接Oracle數(shù)據(jù)庫(kù)(更改數(shù)據(jù)庫(kù)中的記錄并查詢更改后的數(shù)據(jù))

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;//這行和下一行都要先在引用中填加system.data.oracleclient  
  4. using System.Data.OracleClient;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.  
  10. namespace WindowsApplication1  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.  
  19.         private void button1_Click(object sender, EventArgs e)  
  20.         {  
  21.             #region 從region到endregion是手工寫的。別的都是系統(tǒng)自動(dòng)生成的  
  22.             string constring = "data source=wzd;user=wzd;password=wzd;";//定義連接數(shù)據(jù)庫(kù)的字符串  
  23.             OracleConnection conn = new OracleConnection(constring);//進(jìn)行連接  
  24.             try 
  25.             {  
  26.                 conn.Open();//打開指定的連接  
  27.                 OracleCommand com = conn.CreateCommand();  
  28.                 com.CommandText = "select name from fin_ipr_inmaininfo where card_no='0000000002'";//寫好想執(zhí)行的Sql語(yǔ)句  
  29.                 OracleDataReader odr = com.ExecuteReader();  
  30.                 while (odr.Read())//讀取數(shù)據(jù),如果返回為false的話,就說明到記錄集的尾部了   
  31.                 {  
  32.                     this.lbl.Text = odr.GetOracleString(0).ToString();//將讀取到的值顯示到定義的控件中。  
  33.                 }  
  34.                 odr.Close();//關(guān)閉reader.這是一定要寫的  
  35.             }  
  36.             catch 
  37.             {  
  38.                 MessageBox.Show("erro");//如果發(fā)生異常,則提示出錯(cuò)  
  39.             }  
  40.             finally 
  41.             {  
  42.                 conn.Close();//關(guān)閉打開的連接  
  43.             }  
  44.  
  45.             #endregion  
  46.         }  
  47.  
  48.         private void button2_Click(object sender, EventArgs e)  
  49.         {  
  50.             #region 從region到endregion是手工寫的。別的都是系統(tǒng)自動(dòng)生成的  
  51.             string constring = "data source=wzd;user=wzd;password=wzd;";//定義連接數(shù)據(jù)庫(kù)的字符串  
  52.             OracleConnection conn = new OracleConnection(constring);//進(jìn)行連接  
  53.             try 
  54.             {  
  55.                 conn.Open();//打開指定的連接  
  56.                 OracleCommand com = conn.CreateCommand();  
  57.                 com.CommandText = "update fin_ipr_inmaininfo set name='wzd' where card_no='0000000002'";//寫好想執(zhí)行的Sql語(yǔ)句  
  58.                 com.ExecuteNonQuery();  
  59.  
  60.             }  
  61.             catch 
  62.             {  
  63.                 MessageBox.Show("erro");//如果發(fā)生異常,則提示出錯(cuò)  
  64.             }  
  65.             finally 
  66.             {  
  67.                 conn.Close();//關(guān)閉打開的連接  
  68.             }  
  69.  
  70.             #endregion  
  71.         }  
  72.     }  

【編輯推薦】

  1. 淺談C#開發(fā)WinForm
  2. C#靜態(tài)構(gòu)造函數(shù)簡(jiǎn)介
  3. C#實(shí)現(xiàn)ControlTemplate方法
  4. C#驗(yàn)證輸入方法詳解
  5. 淺析C#透明窗體
責(zé)任編輯:彭凡 來源: 百度空間
相關(guān)推薦

2009-08-07 14:02:12

C#數(shù)據(jù)庫(kù)連接字符串

2010-10-26 15:21:11

連接Oracle數(shù)據(jù)庫(kù)

2009-08-20 18:13:17

C#中Access數(shù)據(jù)

2009-08-21 15:06:09

C#連接字符串

2011-07-12 14:08:48

OracleODAC

2010-10-26 15:30:12

連接Oracle數(shù)據(jù)庫(kù)

2009-08-21 14:50:50

C#下MySQL連接字

2011-07-12 14:37:47

ASP.NET鏈接字符串

2009-08-25 15:35:20

C#連接Oracle數(shù)

2009-08-24 18:09:13

C#調(diào)用Oracle數(shù)

2009-09-04 17:23:21

C#數(shù)據(jù)庫(kù)連接對(duì)象

2009-08-25 14:05:06

C#連接數(shù)據(jù)庫(kù)代碼

2009-03-19 10:08:09

C#數(shù)據(jù)庫(kù)查詢

2009-08-07 14:46:59

C#匹配字符串

2009-08-26 13:24:54

C#字符串

2009-08-24 17:06:37

C#字符串

2009-08-07 14:15:21

C#字符串分割

2009-08-07 14:22:56

C#字符串搜索

2009-08-07 14:34:33

C#模式字符串

2009-08-24 13:04:44

操作步驟C#字符串
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)