我用ADOQUERY控件和ADOTABLE控件联合使用时,将ADOTABLE控件做为LOOKUP字段的数据源,在ADOQUERY中增加一个字段做为返回的结果,来支持DBGRID控件的一个字段(这个字段不想显示ID号,想显示具体的名称)的显示但只要这么设置好了一运行就报错?急死我了.
提示EOleException"发生未知错误",我将那个LOOKUP字段去掉就没事了.
我在新增LOOKUP字段时设置也都是对的,KEY FIELDS;LOOKUP KEYS;RESULT FILED;DATA SET;属性都设置没问题.为什么会报错呢?
还有另一个窗体我也这样做的可以运行,在DBGRID控件上看到了下拉列表,点击后看到的想要的值,但是一旦选定一个值时就出错了,不知道为什么.

解决方案 »

  1.   

    我的表A是职员表包括部门ID,表B是部门表包括部门ID和部门名称及其它,
    KEY FIELDS设的是表A的部门ID
    LOOKUP KEYS设的是表B的部门ID
    RESULT FILED设的是表B的部门名称
    DATA SET设的是表B
    部门ID都是INT型4位长度
    部门名称是nvarchar 长度50
    在DBGRID中显示的是职员信息,其中部门一项想显示出具体的部门名称,而不是部门ID,就这样设置了.可还是一运行就出那个提示,请帮看一下是什么问题,类型是一样的INT型怎么会不匹配呢?
      

  2.   

    你确认设置正确了吗??这是最普遍的办法了..
    举个例子吧..
    A表ID; B表ID,NAME;
    一个IDQuery,一个NameQuery(或一个Table就行)
    NameQuery一定要把SQL语句写好才行,或者Table把表连上.
    IDQuery里先添加A表自身的字段(DATA类型)
    再添加一个IDName(LookUp类型)  Type-string.
    Key field--ID(IDQuery);DataSet--NameQuery;
    Lookup Keys--ID(NameQuery);Result Field--Name(NameQuery)
    IDQuery.SQL Select * from A表
    OK...
      

  3.   


    >>> 唉, 簡單,因為我以前碰到過!
    將Lookup關聯字段的LookupCache屬性設為True!!!!=====================================================================
    LookupCache property (TField)Determines whether the values of a lookup field are cached or looked up dynamically every time the current record in the dataset changes.Delphi syntax:property LookupCache: Boolean;C++ syntax:__property bool LookupCache = {read=FLookupCache, write=SetLookupCache, default=0};DescriptionSet LookupCache to true to cache the values of a lookup field when the LookupDataSet is unlikely to change and the number of distinct lookup values is small. Caching lookup values can speed performance, because the lookup values for every set of LookupKeyFields values are preloaded when the DataSet is opened. When the current record in the DataSet changes, the field object can locate its Value in the cache, rather than accessing the LookupDataSet. This performance improvement is especially dramatic if the LookupDataSet is on a network where access is slow.If every record of DataSet has different values for KeyFields, the overhead of locating values in the cache can be greater than any performance benefit provided by the cache. The overhead of locating values in the cache increases with the number of distinct values that can be taken by KeyFields.If LookupDataSet is volatile, caching lookup values can lead to inaccurate results. Call RefreshLookupList to update the values in the lookup cache. RefreshLookupList regenerates the LookupList property, which contains the value of the LookupResultField for every set of LookupKeyFields values.When setting LookupCache at runtime, call RefreshLookupList to initialize the cache.Note: LookupCache is only meaningful if the value of FieldKind is fkLookup.
      

  4.   

    TO:JonnySun()
    不一定要TRUE..我的程序就一直没设..一样可以..
      

  5.   

    感谢大家,我的问题就是LookupCache的问题,设为TRUE就解决了.多谢.