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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42360121/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:23:32  来源:igfitidea点击:

Fill DataTable from Oracle Database Table - C#

c#oraclems-accessdatatable

提问by user7157732

I have successfully built connection string and able to populate table data when the database is Access as:

我已成功构建连接字符串并能够在数据库为 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);
            }

I am new to Oracle though. Can somebody mention what changes to make in above code for Oracle database?

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

回答by Caner Tezcan

You can try this;

你可以试试这个;

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);
}