gpt4 book ai didi

c# - 从 Oracle 数据库表填充 DataTable - C#

转载 作者:行者123 更新时间:2023-11-30 13:44:19 25 4
gpt4 key购买 nike

我已成功构建连接字符串并能够在数据库为 Access 时填充表数据:

DataTable results = new DataTable();
using (OleDbConnection thisConnection = new OleDbConnection(connectionname))
{
OleDbCommand cmd = new OleDbCommand("SELECT * from TABLE_A", thisConnection); //EDIT : change table name for Oracle
thisConnection.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
adapter.Fill(results);
}

虽然我是 Oracle 的新手。有人可以提及对 Oracle 数据库的上述代码进行哪些更改吗?

最佳答案

你可以试试这个;

OracleConnection conn = new OracleConnection("Your Connection string");

//Open the connection to the database
conn.Open();

DataSet dataSet = new DataSet();

OracleCommand cmd = new OracleCommand("your select query");

cmd.CommandType = CommandType.Text;

cmd.Connection = conn;

using (OracleDataAdapter dataAdapter = new OracleDataAdapter())
{
dataAdapter.SelectCommand = cmd;
dataAdapter.Fill(dataSet);
}

关于c# - 从 Oracle 数据库表填充 DataTable - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42360121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com