ado+odbc+db2

littlestcc 2005-01-20 04:07:19
用ado+odbc连db2,创建一个ADOConnection,一个ADODataSet,ADODataSet的sql语句是"select * from test",最简单的查询,连接都ok,把ADODataSet关联到Datasource+DBGrid之后,DBGrid也会显示出各行记录,但都是空行,字段值都是空的,很奇怪,试验了用ADOCommand做insert或update都没问题。
我用同样的连接方式,连到一个本地的access数据库,DBGrid就可以正常显示出数据,这我就奇怪了,为什么连db2的就有问题?

另:test表的字段是varchar的,改成char我也试了,一样

之前发过一个差不多的帖子,http://community.csdn.net/Expert/topic/3740/3740058.xml?temp=.5858118,但是标题不够明确醒目,所以重新发一个,不好意思了!

比较急,请大家帮忙
...全文
266 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaqglxy2004 2005-01-25
  • 打赏
  • 举报
回复

ADOConnection=new TADOConnection(NULL);
ADOQuery =new TADOQuery(NULL);
DataSource=new TDataSource(NULL);

ADOConnection->ConnectionString="Provider=MSDASQL.1;Password=asd;Persist Security Info=True;User ID=db2admin;Data Source=YLBX";
ADOConnection->LoginPrompt=False;

ADOQuery->Connection=ADOConnection;

ADOQuery->Close();
ADOQuery->SQL->Clear();

ADOQuery->SQL->Add("select * from ylbx.czyxx");
ADOQuery->Open();
DataSource->DataSet=ADOQuery;
DBGrid1->DataSource=DataSource;
littlestcc 2005-01-24
  • 打赏
  • 举报
回复
我试了一下,发现我在帖子一开始描述的charactor和varchar类型的字段显示为空的问题应该也是由于codepage不一样导致的,db2建库的时候是用的iso 8859-1,BCB应用程序用的是GBK,可能取出来之后变成了乱码,所以就显示成空的了。有没有什么办法可以在取字段值之前先把8859-1编码的转成GBK的??(前提条件,我的DB2数据库不能重建库,只能用8859-1)
littlestcc 2005-01-24
  • 打赏
  • 举报
回复
换成TQuery的话就会出现我之前说过的codepage不兼容的问题,即使我通过命令行把db2的代码页环境改成819了,在BCB里运行还是说codepage不兼容
pcclever 2005-01-22
  • 打赏
  • 举报
回复
我不知道楼主用的是什么版本,我用的是BCB5.0+odbc+db2 5.2

发现ADO操作db2简直就是一场灾难。

建议换成TQuery,非常稳定。
littlestcc 2005-01-21
  • 打赏
  • 举报
回复
to blackeviler(风清扬) :
我发现integer的字段都没问题,charactor和varchar的都是空的,这又是为什么呢?
littlestcc 2005-01-21
  • 打赏
  • 举报
回复
问题1:直接用ADO连DB2的话是不是需要有"IBM OLE DB Provider for DB2 Servers"?,这个好像是装DB2客户端的时候带的,系统默认好像是没有OLE DB Provider for DB2的

问题2:直接用ADO连DB2是不是这样用:在设置ADOConnection的时候OLE DB提供程序选择"IBM OLE DB Provider for DB2 Servers",然后数据源填之前用DB2客户端配置的数据库别名

问题3:用问题2的配置方式测试连接ok,运行后报codepage不兼容的错,我又到db2命令行把codepage手工改成819,再次运行还是会报,怎么办?
lvjack 2005-01-20
  • 打赏
  • 举报
回复
直接ADO连接DB2试试
blackeviler 2005-01-20
  • 打赏
  • 举报
回复
1.使用ADO,还要使用ODBC?这个我不太明白,一般如果使用ADO,就不需要再使用ODBC。

2.楼主可以测试一下,估计是DB2中的字段格式有一些问题,比如可以改成整数测试一下即可。
就知道问题出在何处了。
OTL介绍: OTL 是 Oracle, Odbc and DB2-CLI Template Library 的缩写,是一个C++操控关系数据库的模板库,最新版本4.0.104,参见http://otl.sourceforge.net/ 优点:a. 跨平台 b. 运行效率高,与C语言直接调用API相当 c. 开发效率高,起码比ADO.net使用起来更简单,更简洁 d. 部署容易,不需要ADO组件,不需要.net framework 等 缺点: a. 只有C++才可以使用她 b. 说明以及范例不足(已附带了686个实例) This document describes the Oracle, ODBC and DB2-CLI Template Library, Version 4.0 (OTL 4.0). OTL 4.0 is a C++ library based on C++ templates. OTL 4.0 was designed as a combination of a C++ template framework and OTL-adapters. The framework is a generic implementation of the concept of OTL streams. The OTL-adapters are thin wrappers around the database APIs and are used as class type parameters to be passed into the template framework. OTL 4.0 covers the functionality of a full featured C++ database access library with just a handful of classes: otl_stream, otl_connect, otl_exception, otl_long_string, and several template PL/SQL (Oracle) table container classes, generated from the template framework and the OTL-adapters. The OTL code gets expanded into direct database API function calls, so it provides very decent performance (only 10-15% overhead, compared with the database APIs themselves) and reliability in multi-processor environments as well as traditional batch programs. OTL 4.0, being a template library, is highly portable since it is self-sufficient and compact enough. OTL 4.0 is ANSI C++ compliant (ANSI C++ typecasts, clean templatized code, etc.), tightly integrated with the Standard Template Library (STL) via STL-compliant stream iterators, and natively supports the STL std::string's in otl_stream's. OTL integrates with ACE, and supports ACE_TStrings. OTL 4.0 supports all versions of Oracle starting with 7.3 (natively via the corresponding version of the OCI), DB2 UDB LUW / zOS (natively via DB2 CLI), MS SQL Server 2005/2008 (natively via SNAC), Informix 11 (natively via Informix CLI), TimesTen 7 and higher (natively TimesTen CLI), SAP-MAX/DB (natively via SAP/DB CLI), ODBC 3.x as well as ODBC 2.5 (for legacy applications) compliant data sources in MS Windows, Linux/Unix/Mac OS X (via unixodbc and iODBC driver managers): Sybase, MySQL, PostgreSQL, EnterpriseDB, SQLite, MS ACCESS, Firebird, etc. The list of supported database back ends is growing. In the last few years, transition from the 32-bit platforms to the 64-bit platforms has occurred: OTL's source code is portable, and it support both 32-bit and 64-bit C++ compilers. Also, OTL supports UTF-8 and UTF-16 for Oracle, and UTF-16 for the rest of the database types, when the underlying database API / ODBC driver supports it.

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧