博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#连接oracle数据库
阅读量:4610 次
发布时间:2019-06-09

本文共 2146 字,大约阅读时间需要 7 分钟。

using System;using System.IO;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.OracleClient;using System.Drawing;using System.Text;using System.Windows.Forms;//测试数据库连接namespace dbTest{    public partial class Form1 : Form    {        string[] table;        int i = 0;        public Form1()        {            table = new string[20];            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            //测试,写字符串到文件(文件名:2012-10-10)            string checkStr = "select count(*) from emp";           //时间命名文件            string myFileName = "c:\\" + DateTime.Today.ToShortDateString() + ".txt";            //建立文件流            FileStream fs = new FileStream(myFileName, FileMode.OpenOrCreate);            //建立输入流对象            StreamWriter sw = new StreamWriter(fs);            sw.Write(checkStr);            sw.Flush();            sw.Close();            try            {                //连接 用OracleCommand方法进行简单查询                  string ConString = "Data Source=TEST;user=TEST001;password=123456";                OracleConnection OraConn = new OracleConnection(ConString);                //查询语句                OracleCommand OraCmd = new OracleCommand("select empno from emp", OraConn);                //打开数据连接                OraConn.Open();                //存储过程测试                  //OraCmd.CommandText="proc_test";                //OraCmd.CommandType=CommandType.StoredProcedure;                //OracleCommandBuilder.DeriveParameters(OraCmd);                             DataSet ds1;                ds1 = new DataSet();                OracleDataAdapter da1 = new OracleDataAdapter(OraCmd);//取出数据                   da1.Fill(ds1);                DataTable dt = ds1.Tables[0];                this.dataGridView1.DataSource = dt.DefaultView;                this.dataGridView1.Refresh();//刷新数据控件                //关闭数据连接                OraConn.Close();            }            catch (Exception ex)            {                MessageBox.Show("出错了!!");            }        }    }    }

 

转载于:https://www.cnblogs.com/Cryking/archive/2012/11/13/2767692.html

你可能感兴趣的文章
CSS3 新属性兼容性测试
查看>>
js闭包
查看>>
Oralce导入数据库出现某一列的值太大
查看>>
Union和Union All 的区别
查看>>
Git的安装和使用教程详解
查看>>
lsof命令详解
查看>>
常用模块,异常处理
查看>>
父窗口与子窗口之间的传值
查看>>
eclipse 找不到 tomcat 的解决方案
查看>>
HDU 1890--Robotic Sort(Splay Tree)
查看>>
connection string for Excel/Access 2010
查看>>
【转】【Python】Python中的__init__.py与模块导入(from import 找不到模块的问题)
查看>>
学习wavenet_vocoder之环境配置
查看>>
常用Maven命令
查看>>
Docker启动mysql的坑2
查看>>
j2ee爬坑行之二 servlet
查看>>
JAVA基础入门(JDK、eclipse下载安装)
查看>>
最基础的applet运用--在applet上画线
查看>>
布局大全
查看>>
eclipse中安装tomcat插件
查看>>