在数据库中使用ODBC驱动程序查询结果,但在C#中不填充数据库,没有错误
刚刚开始使用Windows 11并为32位和64位安装了Oracle驱动程序,使用C#从Oracle数据库中获取数据。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient;
namespace ApexAutoEmailConsol
{
static class ServiceLog
{
static String connectionString = "Dsn=Prod21_32;uid=ebseb;pwd=ebseb";
static string strQuery = string.Empty;
public static string OutstandingInvoices()
{
try
{
OdbcConnection oCon = new OdbcConnection();
oCon.ConnectionString = connectionString;
oCon.Open();
DataTable dtSales = new DataTable();
strQuery = "SELECT * from apps.org_organization_definitions HO";
// if I run above query in Toad it's giving result.
OdbcDataAdapter myAdp = new OdbcDataAdapter(strQuery, oCon);
myAdp.Fill(dtSales);
//Adapter not filling data to the datatable.
if (dtSales.Rows.Count <= 0)
{
return "";
}
return strReturn;
}
catch (Exception Ex)
{
WriteErrorLog(Ex.ToString());
return "";
}
}
}
当我复制Strquery
并在蟾蜍上运行时,获取结果,但数据仍然为空。
问题是什么?同一代码在我的Windows10计算机上正常工作。
Just started using windows 11 and installed Oracle drivers for 32Bit and 64Bit, wrote program using C# to fetch data from Oracle database.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Data.Odbc;
using System.Data;
using System.Data.SqlClient;
namespace ApexAutoEmailConsol
{
static class ServiceLog
{
static String connectionString = "Dsn=Prod21_32;uid=ebseb;pwd=ebseb";
static string strQuery = string.Empty;
public static string OutstandingInvoices()
{
try
{
OdbcConnection oCon = new OdbcConnection();
oCon.ConnectionString = connectionString;
oCon.Open();
DataTable dtSales = new DataTable();
strQuery = "SELECT * from apps.org_organization_definitions HO";
// if I run above query in Toad it's giving result.
OdbcDataAdapter myAdp = new OdbcDataAdapter(strQuery, oCon);
myAdp.Fill(dtSales);
//Adapter not filling data to the datatable.
if (dtSales.Rows.Count <= 0)
{
return "";
}
return strReturn;
}
catch (Exception Ex)
{
WriteErrorLog(Ex.ToString());
return "";
}
}
}
When I copy strQuery
and run on Toad, getting result but datatable is still empty.
What is the problem? The same code is working perfect on my Windows10 machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
un
提交
TED数据仅在创建它的会话中可见(并且,如果没有CONDE> CONDE> CONDE> CONDE> CODER
在会话结束时将可见。泰德)。如果您看不到另一个会话(C#)的数据,请确保已在SQL客户端(TOAD)中发布了commit
命令。如果您已经发布了
commit
,但仍然看不到数据,请确保SQL客户端(TOAD)和C#程序都连接到同一数据库,并在查询同一用户的架构该数据库。Un
COMMIT
ted data is only visible within the session that created it (and willROLLBACK
at the end of the session if it has not beenCOMMIT
ted). If you can't see the data from another session (C#) then make sure you have issued aCOMMIT
command in the SQL client (Toad).If you have issued a
COMMIT
and still can't see the data then make sure that both the SQL Client (Toad) and the C# program are connecting to the same database and are querying the same user's schema of that database.这是非常独特的问题,大约在2年前,我用另一台机器遇到了它,在那里我无法在蟾蜍中获得一些查询结果。一些查询正在工作,但是一些具有特定表格的查询是空的结果。那个时候,我在环境变量中添加了以下语言设置并进行了工作。
nls_lang = American_america.utf8
在我的新机器中使用了相同的使用,现在可以通过Visual Studio 2022获得结果。
It's very unique problem, I had it around 2 years ago with my another machine, where I was not able to get some query result in Toad. Some queries are working but some of with specific table in joing was giving empty result. That time I added following language setting in my environment variable and was worked.
NLS_LANG = American_America.UTF8
Used same in my new machine and now am getting result with Visual Studio 2022.