C#连接Oracle数据库查询数据
作者:应用开发 来源:IT科技 浏览: 【大中小】 发布时间:2025-11-04 00:29:22 评论数:

复制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,接O据库 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的查询话,就说明到记录集的接O据库尾部了 { this.lbl.Text = odr.GetOracleString(0).ToString();//将读取到的值显示到定义的网站模板控件中。 } odr.Close();//关闭reader.这是数数据一定要写的 } catch { MessageBox.Show("erro");//如果发生异常,则提示出错 } finally { conn.Close();//关闭打开的查询连接 } #endregion } } } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.
