oracle OracleDataAdapter 未从 Query 填充 DataTable

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9983499/
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 00:42:14  来源:igfitidea点击:

OracleDataAdapter is not filling DataTable from Query

c#sql-serveroracle

提问by Matthew

I am writing an C# application for both SQL Server and Oracle Databases that is defined in my application configuration file. When I run the code in the SQL Server environment, it works fine. I get the correct results.

我正在为我的应用程序配置文件中定义的 SQL Server 和 Oracle 数据库编写 C# 应用程序。当我在 SQL Server 环境中运行代码时,它工作正常。我得到了正确的结果。

The working SQL Server Code is here:

工作的 SQL Server 代码在这里:

sqlConn.Open();
stmt = "SELECT ACTION_ID, ACTION FROM DB.ACTIONS WHERE ACTION_DATE < GETDATE() AND STATUS = 'Pending'";
SqlDataAdapter sqlAdapt = new SqlDataAdapter(stmt, sqlConn);
sqlAdapt.Fill(dt);
sqlConn.Close();

The Oracle Code that is not working is as follows:

不工作的Oracle代码如下:

oraConn.Open();
stmt = "SELECT ACTION_ID, ACTION FROM DB.ACTIONS WHERE ACTION_DATE < SYSDATE AND STATUS = 'Pending'";
OracleDataAdapter oraAdapt = new OracleDataAdapter(stmt, oraConn);
oraAdapt.Fill(dt);
oraConn.Close();

I'm trying to fill the datatable dt with the results. I have tried using a DataSet first and filling the DataTable with the DataSet, but that didn't work in Oracle when it did in SQL Server. It seems like there's something simple missing.

我正在尝试用结果填充数据表 dt。我曾尝试先使用 DataSet 并用 DataSet 填充 DataTable,但是在 SQL Server 中它在 Oracle 中不起作用。似乎缺少一些简单的东西。

I'm not getting any errors, I'm just getting a 0 result set from Oracle even though I know there's data there to be pulled.

我没有收到任何错误,我只是从 Oracle 获得了一个 0 结果集,即使我知道那里有数据要提取。

采纳答案by Matthew

The issue was the DBO account I was logging into the database with did not have permissions to the table. I ran a simple grant and it worked great.

问题是我登录到数据库的 DBO 帐户没有对该表的权限。我运行了一个简单的赠款,效果很好。

    GRANT SELECT ON DB.ACTIONS TO USER;

回答by Turbot

My suggestion is to change your code to separate the diagnostic level.

我的建议是更改您的代码以分离诊断级别。

1) replace the statement with simple "select sysdate from dual;" to see if there is any row return.

1) 用简单的“select sysdate from dual”替换语句;查看是否有任何行返回。

2) if nothing return, it might be your connection issue. view your connection property.

2)如果没有任何返回,则可能是您的连接问题。查看您的连接属性。

3) if something is return but not fill to dataset, try to use oracle reader to throw the output and see indeed the result.

3)如果有东西返回但没有填充到数据集,尝试使用oracle reader抛出输出并查看结果。

Hope this will help you.

希望这会帮助你。

回答by arturro

Run query directly on the DB (for example using sqlplus, TOAD, SQLDEveloper etc.). Does it return anything? If not:

直接在数据库上运行查询(例如使用 sqlplus、TOAD、SQLDEveloper 等)。它会返回任何东西吗?如果不:

a) In SQL Server text comparison (STATUS = 'Pending') is case insensitive in Oracle it is case sensitive. Maybe you have data in status column like 'PENDING' for example ?

a) 在 SQL Server 文本比较中 (STATUS = 'Pending') 在 Oracle 中不区分大小写,它区分大小写。例如,也许您在状态列中有数据,例如“PENDING”?

b) Is ACTION_DATE is date datatype? If it is varchar it won't work.

b) ACTION_DATE 是日期数据类型吗?如果它是 varchar 它将不起作用。

Hope it helps.

希望能帮助到你。