首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

100分的有关问题,三层数据库应用程序中,主/从结构中取不到从表,

2012-02-16 
100分的问题,三层数据库应用程序中,主/从结构中取不到从表,急在C++Builder6企业版+Update4环境下,按照李维

100分的问题,三层数据库应用程序中,主/从结构中取不到从表,急
在C++Builder6企业版   +   Update4   环境下,按照李维的 < <Delphi   5.x   分布式多层应用系统篇> > 第2章   2-35页中的 "使用巢状数据库表实现Master/Detail的应用系统 "做了N遍,在客户端数据模块中第二个(从表)TClientDataSet的DataField属性中也没有出现第一个(主表)TClientDataSet中内含的TADODataSet(该控件指向从表),为什么?

主要过程如下:
 

应用程序服务端如下:

在工程中加入Remote   Data   Module,  

在Remote   Data   Module中加入以下控件:
 
1.   ADOConnection1控件中:
      设置ConnectionString属性连接到SQL   Server的pubs数据库,测试成功.
      Active   =   true;


2.   ADODataSet1控件中:
      Connection   =   ADOConnection1;
      CommandText   =   select   *   from   publishers;     //主表
      Active   =   true;


3.   DataSource1控件中:
      DataSet   =   ADODataSet1;


4.   ADODataSet2控件中:
      Connection   =   ADOConnection1;
      CommandText   =   select   *   from   books;     //从表
      DataSource   =   DataSource1;
      MasterFields   =   pub_id;               //主从表的连接字段
      Active   =   true;


5.   DataSetProvider1控件中:
      DataSet   =   ADODataSet1;

其他都保留原默认值,编译运行,成功.


客户端如下:

在工程中加入Data   Module,

在DataModule1中加入以下控件:

1.   SocketConnection1
      LoginPrompt   =   false;
      Address   =                         //这里输入运行应用服务器程序主机的IP地址
      ServerName   =                   //选取上面的应用服务器名
      ServerGUID   =                   //??   奇怪,这里并有自动取得上面应用服务程序的ID
      Connected   =   true;


2.   ClientDataSet1    //主表使用
      RemoteServer   =   SocketConnection1;
      ProviderName   =   DataSetProvider1;         //指向应用服务器主表的输出
      Active   =   true;
      //补充说明:在FieldDefs属性中可以看到有主表的所有字段及ADODataSet2存在

3.   DataSource1
      DataSet   =   ClientDataSet1;

    //加入DBGrid1控件,并设置DataSource   =   DCustomerData-> DataSource1后,能正常显示出主表数据库中的数据.


4.   ClientDataSet2    //从表使用
      DataField   =               //按李维老师的教程,应该有ClientDataSet1主表FieldDefs属性中的ADODataSet2可供选取,但这里却什么都没有--是空白!


使用了以下系统平台,问题还是存在:

Windows   2000   Server   +   BCB6(Update4)   +   SQL   Server企业版;

Windows   XP(sp2)   BCB6(Update4)   +   SQL   Server开发版;

Windows   XP(sp2)   BCB20066(Update2)   +   SQL   Server开发版;


    为什么会是这样?是C++Builder6的问题?如何解决?

[解决办法]
选中客户端处理主表的ClientDataSet,在Object TreeView窗口中定位到Fields,点击右键,选取"Add fields..."--> OK

这可能是BCB的一个Bug吧,在Delphi中就不需要这样做.
------解决方案--------------------


1. SocketConnection1
LoginPrompt = false;
Address = //这里输入运行应用服务器程序主机的IP地址
ServerName = //选取上面的应用服务器名
ServerGUID = //?? 奇怪,这里并有自动取得上面应用服务程序的ID
Connected = true;
----------------------------------
__property AnsiString ServerGUID = {read=GetServerGUID, write=SetServerGUID};

GUID __fastcall GetServerCLSID(void);

Description

GetServerCLSID is used internally to obtain the GUID for the application server.

In most cases, GetServerCLSID returns the value of the ServerGUID property. However, if the application server was specified using the ServerName property, and the application server was not registered when the ServerName property was set, ServerGUID will not represent the application server抯 GUID. GetServerCLSID can return a GUID that only becomes available when a connection is opened.

If neither the ServerName nor the ServerGUID property is set, GetServerCLSID throws an exception.

热点排行