在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//关键代码
string connectionString;
string queryString;
// 连接字符串1
connectionString = "Data Source=127.0.0.1/orcl;User ID=test;PassWord=test";
//查询语句
queryString = "SELECT * FROM TEST";
OracleConnection myConnection = new OracleConnection(connectionString);
OracleCommand myORACCommand = myConnection.CreateCommand();
myORACCommand.CommandText = queryString;
myConnection.Open();
OracleDataAdapter oraDA = new OracleDataAdapter(myORACCommand);
DataSet ds = new DataSet();
oraDA.Fill(ds);
myConnection.Close();
DataTable dtbl = ds.Tables[0];
this.dataGridView1.DataSource = dtbl;
完整版代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OracleClient;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) //按钮事件
{
string connectionString;
string queryString;
// 连接字符串
connectionString = "Data Source=127.0.0.1/orcl;User ID=test;PassWord=test";
//查询语句
queryString = "SELECT * FROM TEST";
OracleConnection myConnection = new OracleConnection(connectionString);
OracleCommand myORACCommand = myConnection.CreateCommand();
myORACCommand.CommandText = queryString;
myConnection.Open();
OracleDataAdapter oraDA = new OracleDataAdapter(myORACCommand);
DataSet ds = new DataSet();
oraDA.Fill(ds);
myConnection.Close();
DataTable dtbl = ds.Tables[0];
this.dataGridView1.DataSource = dtbl;
}
}
}
查询效果
一起学习,一起进步。 |
请发表评论