【发布时间】:2022-01-11 02:31:08
【问题描述】:
您好,我有一个带有 3 列 NOME、COGNOME、NUMTELEFONO 的表 PROVA 的 oracle 数据库。 我正在搜索用包含在表中的值来更新我在 c# 中的 gridview。 这是我的代码,在 button1_Click() 方法中,我需要在我的 gridview c# 应用程序中显示 db 值。有人可以帮我写代码吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Oracle.ManagedDataAccess;
namespace dbOracleForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
String connectionString = "Data Source = (DESCRIPTION = "+
"(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))" +
"(CONNECT_DATA = " +
" (SERVER = DEDICATED) " +
" (SERVICE_NAME = orcl.home) " +
")"+
"); User Id = system;password = orcl;";
OracleConnection con = new OracleConnection();
con.ConnectionString = connectionString;
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "SELECT NOME, COGNOME, NUMTELEFONO FROM PROVA ORDER BY COGNOME DESC";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dataGridView1.DataSource(dt);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
【问题讨论】:
-
这是另一个可能有用的帖子:docs.oracle.com/cd/E20434_01/doc/win.112/e23174/…
标签: c# .net oracle oracle11g sql-plus-dot-net