Board index » delphi » why TDBLookupComboBox cannot work naturally?

why TDBLookupComboBox cannot work naturally?

  I'm using Delphi 5 Enterprise + Sybase 11.9, When I connect
table with native sybase driver, The DBLookupComboBox seems work unnaturally
and it can work with ODBC.
  it seems that DBLookupComboBox can show content of list field according to
key field, when length of content of key field fit
with field length defined in sybase table. but it don't work when length of
content of key field less than field length defined in sybase table.
  What can i do for it? can anybody help?
 

Re:why TDBLookupComboBox cannot work naturally?


Sit down.
Drink a glass of cold water.
Rethink the problem and rephrase the question.
I really don't understand it. What is "working naturally"? What does not
work or how do you determine it doesn't work? How is key field defined?
Error messages, simptoms,....

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si
No questions via email, unless explicitly invited.

Quote
kjerry wrote in message <3a4b156c$1_1@dnews>...
>  I'm using Delphi 5 Enterprise + Sybase 11.9, When I connect
>table with native sybase driver, The DBLookupComboBox seems work
unnaturally
>and it can work with ODBC.
>  it seems that DBLookupComboBox can show content of list field according
to
>key field, when length of content of key field fit
>with field length defined in sybase table. but it don't work when length of
>content of key field less than field length defined in sybase table.

>  What can i do for it? can anybody help?

Re:why TDBLookupComboBox cannot work naturally?


Hi, Robert Cerny
  the question in detail as following:

unit1.dfm:

object Form1: TForm1
  Left = 192
  Top = 107
  Width = 418
  Height = 285
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBLookupComboBox1: TDBLookupComboBox
    Left = 88
    Top = 184
    Width = 145
    Height = 21
    DataField = 'state'
    DataSource = DataSource1
    KeyField = 'code'
    ListField = 'name'
    ListSource = DataSource2
    TabOrder = 0
  end
  object DBNavigator1: TDBNavigator
    Left = 96
    Top = 224
    Width = 240
    Height = 25
    DataSource = DataSource1
    TabOrder = 1
  end
  object DBGrid1: TDBGrid
    Left = 0
    Top = 0
    Width = 410
    Height = 169
    Align = alTop
    DataSource = DataSource1
    TabOrder = 2
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object Query1: TQuery
    Active = True
    DatabaseName = 'htltoll'
    RequestLive = True
    SQL.Strings = (
      'SELECT * FROM employee')
    Left = 56
    Top = 216
  end
  object DataSource1: TDataSource
    DataSet = Query1
    Left = 24
    Top = 216
  end
  object Query2: TQuery
    Active = True
    DatabaseName = 'htltoll'
    Constrained = True
    SQL.Strings = (
      'SELECT * FROM state')
    Left = 304
    Top = 184
  end
  object DataSource2: TDataSource
    DataSet = Query2
    Left = 336
    Top = 184
  end
end

unit1.pas:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, ExtCtrls, DBCtrls, Db, DBTables;

type
  TForm1 = class(TForm)
    Query1: TQuery;
    DataSource1: TDataSource;
    Query2: TQuery;
    DataSource2: TDataSource;
    DBLookupComboBox1: TDBLookupComboBox;
    DBNavigator1: TDBNavigator;
    DBGrid1: TDBGrid;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

end.

and when employee.state = 'CA'(2 byte length), DbLookupComboBox can show
text 'California', when employee.state = 'L'(1 byte length), It can not show
text 'Los' But empty. in table state,
two rows exists:
        row 1. code = 'L', name ='Los'
        row 2. code = 'CA', name = 'California'
tables defined in sybase as following:
     state(code char(2) primary key, name varchar(20)
     employee(id char(6) primary key, name varchar(20), state char(2)
reference foreign key state.code)

  Could you give me any help? thanks!

                                   kjerry

Quote
Robert Cerny <robert.qwe.ce...@neosys.xrs.qwe.si> wrote in message

news:92fgfk.1so.1@neosys.xrs.si...
Quote
> Sit down.
> Drink a glass of cold water.
> Rethink the problem and rephrase the question.
> I really don't understand it. What is "working naturally"? What does not
> work or how do you determine it doesn't work? How is key field defined?
> Error messages, simptoms,....

> --
> ----------------------
> Regards
> Robert Cerny
> Remove both qwe when replying
> email: robert.qwe.ce...@neosys.xrs.qwe.si

> No questions via email, unless explicitly invited.
> kjerry wrote in message <3a4b156c$1_1@dnews>...
> >  I'm using Delphi 5 Enterprise + Sybase 11.9, When I connect
> >table with native sybase driver, The DBLookupComboBox seems work
> unnaturally
> >and it can work with ODBC.
> >  it seems that DBLookupComboBox can show content of list field according
> to
> >key field, when length of content of key field fit
> >with field length defined in sybase table. but it don't work when length
of
> >content of key field less than field length defined in sybase table.

> >  What can i do for it? can anybody help?

Re:why TDBLookupComboBox cannot work naturally?


Quote
kjerry wrote:
> and when employee.state = 'CA'(2 byte length), DbLookupComboBox can show
> text 'California', when employee.state = 'L'(1 byte length), It can not show
> text 'Los' But empty. in table state,
> two rows exists:
>         row 1. code = 'L', name ='Los'
>         row 2. code = 'CA', name = 'California'
> tables defined in sybase as following:
>      state(code char(2) primary key, name varchar(20)
>      employee(id char(6) primary key, name varchar(20), state char(2)
> reference foreign key state.code)

--------------------------
I don't know sysbase, but it is possible you have ' L' or 'L ' in one of
your table. Just check it.

CU
Wlodek

--
virtual office in a virtual home
means you'll never have to drive
through the wrong part of town
-Chumbawamba

Re:why TDBLookupComboBox cannot work naturally?


It's not a DBCombo problem.
If you define a field as CHAR, it means fixed size string, so if data is
shorter, the server will pad it with blanks.
So, you enter the value 'L', but when retrieving you get 'L ' (space added),
DBCombo has 'L' associated with 'Los', but nothing with 'L ', so it doesn't
show anything.
Workaround is to have all codes two character or define field as VARCHAR(2).
--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.
[snip]

Quote
>and when employee.state = 'CA'(2 byte length), DbLookupComboBox can show
>text 'California', when employee.state = 'L'(1 byte length), It can not
show
>text 'Los' But empty. in table state,
>two rows exists:
>        row 1. code = 'L', name ='Los'
>        row 2. code = 'CA', name = 'California'
>tables defined in sybase as following:
>     state(code char(2) primary key, name varchar(20)
>     employee(id char(6) primary key, name varchar(20), state char(2)
>reference foreign key state.code)

Re:why TDBLookupComboBox cannot work naturally?


  Yeah, It's really what i think.Thanks
  But is there any other way to solve this problem expect changing Char(2)
to Varchar(2).

   Thank you!
                            kjerry

Quote
Robert Cerny <robert.qwe.ce...@neosys.xrs.qwe.si> wrote in message

news:92ido8.1l0.1@neosys.xrs.si...
Quote
> It's not a DBCombo problem.
> If you define a field as CHAR, it means fixed size string, so if data is
> shorter, the server will pad it with blanks.
> So, you enter the value 'L', but when retrieving you get 'L ' (space
added),
> DBCombo has 'L' associated with 'Los', but nothing with 'L ', so it
doesn't
> show anything.
> Workaround is to have all codes two character or define field as
VARCHAR(2).
> --
> ----------------------
> Regards
> Robert Cerny
> Remove both qwe when replying
> email: robert.qwe.ce...@neosys.xrs.qwe.si

> No questions via email, unless explicitly invited.
> [snip]

Other Threads