zoukankan      html  css  js  c++  java
  • C# 连接Oracle 11g 无需安装Oracle客户端

    1.首先到Oracle网站上下载ODAC

    下载地址1:http://download.csdn.net/detail/easyboot/9456476

    下载地址2:http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html

    2.下载的文件解压后找到Oracle.ManagedDataAccess.dll

    3.将DLL文件拷贝到你的项目目录下,并引用进来即可

     

    4.测试代码如下所示

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Oracle.ManagedDataAccess.Client; //加入引用
    using Oracle.ManagedDataAccess.Types; //加入引用


    namespace ConnOracle
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }


            public void ConnOracle()
            {
                try
                {
                    string connStr = "User Id=userid;Password=userpwd;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myDB)))";
                    using (var conn = new OracleConnection(connStr))
                    {
                        conn.Open();
                        DataSet ds = new DataSet();
                        string sql = "select *  from user.testtable";
                        OracleDataAdapter oda = new OracleDataAdapter(sql, conn);
                        oda.Fill(ds);
                        DataTable dt = ds.Tables[0];
                        dataGridView1.DataSource = dt;


                    }
                }
                catch (OracleException ex)
                {
                    throw new Exception(ex.Message);
                }
            }


            private void button1_Click(object sender, EventArgs e)
            {
                ConnOracle();
            }
        }
    }

  • 相关阅读:
    struts 简单配置运用做一个简单的注册
    hibernate 锁 (转)
    Hibernate 缓存机制(转)
    解决Hibernate:could not initialize proxy
    el 表达式用法(转)
    自动生成Hibernate框架结构
    封装hibernate 初始化类 方便调用 (静态单例模式)
    构建hibernate 框架实现增删改查功能
    JSON 与 对象 、集合 之间的转换(转)
    Ajax 引擎 传输数据的方法
  • 原文地址:https://www.cnblogs.com/chengeng/p/10531052.html
Copyright © 2011-2022 走看看