通过nuget安装ManagedDataAccess
(自动生成的config里面的配置都可以删掉)
winform程序,拖出一个datagridview和button
using Oracle.ManagedDataAccess.Client;
using System;
using System.Data;
using System.Windows.Forms;
namespace oracle
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s = "Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 数据库ip)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)));User ID=数据库用户名;PassWord=数据库密码";
string queryString = "select * from ztwrdata where testtime >='2016/09/13' and X<>'--' AND Y<>'--' and ROWNUM<=10";
OracleConnection myConnection = new OracleConnection(s);
OracleCommand myORACCommand = myConnection.CreateCommand();
myORACCommand.CommandText = queryString;
myConnection.Open();
OracleDataAdapter oraDA = new OracleDataAdapter(myORACCommand);
DataSet ds = new DataSet();
oraDA.Fill(ds);
DataTable dtbl = ds.Tables[0];
dataGridView1.DataSource = dtbl;
myConnection.Close();
}
}
}