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();
}
}
}
---------------------
作者:easyboot
来源:CSDN
原文:https://blog.csdn.net/easyboot/article/details/50834837
版权声明:本文为博主原创文章,转载请附上博文链接!
原文地址:https://www.cnblogs.com/chengeng/p/10531052.html