Q&A

  • db에서 이름중 한자만 선택 하면 ...
디비에서 이름 한 자(예로 '김' 만 치고 엔터시) 선택하면 디비에 나와 있는 이름들 중 김으로 시작되면 다 리스트 박스에 나타나게 해서 Edit2에 넣는 프로 그램 입니다.

디비는 DB Desktop 이구 여.. 테이블 명은요...check이구여.. 흠...

프로그램 소스는...



unit Unit1;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

DBTables, Db, ExtCtrls, StdCtrls;



type

TForm1 = class(TForm)

MNAME: TEdit;

MCOMPANY: TEdit;

LBIName: TListBox;

Panel1: TPanel;

Panel2: TPanel;

QTransaction: TQuery;

Database1: TDatabase;

procedure MNAMEKeyPress(Sender: TObject; var Key: Char);

private

{ Private declarations }

public

{ Public declarations }

end;



var

Form1: TForm1;



implementation



{$R *.DFM}



procedure TForm1.MNAMEKeyPress(Sender: TObject; var Key: Char);

var

i:Byte;

m_MName:String;

begin

if Key=#13 then

begin

if MNAME.Text='' then

Exit;

With QTransaction do

Begin

SQL.BeginUpdate;

SQL.Clear;

SQL.Add('SELECT Name,Company');

SQL.Add(' FROM CHECK');

SQL.Add(' WHERE Name LIKE :MNAME');

SQL.EndUpdate;

ParamByName('Name').AsString:=MNAME.Text+'%';

Open;

if RecordCount = 0 then

begin

Exit;

end else

begin

Key :=#0;

LBIName.Items.Beginupdate;

LBIName.Items.Clear;

while not EOF do



Begin

m_MName := FindField('Name').AsString;

for i:= 1 to - length(m_MName)do

m_MName := m_MName+'';

LBIName.Items.Add(m_MName+'-'+

FindField('Company').AsString);

Next;

end;

LBIName.Items.EndUpdate;

LBIName.ItemIndex := 0;

if LBIName.Items.Count = 1 then

begin

SendMessage(LBIName.Handle,WM_CHAR,13,0);

end else

begin

LBIName.Height :=100;

LBIName.BringToFront;

LBIName.Visible := True;

LBIName.SetFocus;

end;

end;

end;

end;



end;



end.

입니다.. 고수님들의 많은 협조 부탁 드립니다...

흠..

참고

LBIName은 리스트 박스구...

MNAME은 Edit1이구..

MCOMPANY는 Edit2이구

Table name ; check

field Name,Company입니다..

그럼 좋은 조언 기다리겠습니다..



1  COMMENTS
  • Profile
    유레카 2000.06.20 04:53
    With QTransaction do

    Begin

    SQL.BeginUpdate;

    SQL.Clear;

    SQL.Add('SELECT Name,Company');

    SQL.Add(' FROM CHECK');

    SQL.Add(' WHERE Name LIKE :MNAME');

    SQL.EndUpdate;

    ParamByName('MNAME').AsString:=MNAME.Text+'%'; <=== 여기가 틀렸네요.

    Open;



    그리고 나서

    LBIName.Items.Clear;

    if QTransaction.RecordCount <> 0 then

    begin

    while not QTransaction.Eof do

    begin

    LBIName..Items.Add(QTransaction.FieldByName('Name').AsString);

    QTransaction.Next;

    end;

    end;

    이러면 쿼리된 내용이 리스트박스에 들어가겠죠..



    나머진 알아서..^^







    왕촙.. 입니다.. wrote:

    > 디비에서 이름 한 자(예로 '김' 만 치고 엔터시) 선택하면 디비에 나와 있는 이름들 중 김으로 시작되면 다 리스트 박스에 나타나게 해서 Edit2에 넣는 프로 그램 입니다.

    > 디비는 DB Desktop 이구 여.. 테이블 명은요...check이구여.. 흠...

    > 프로그램 소스는...

    >

    > unit Unit1;

    >

    > interface

    >

    > uses

    > Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    > DBTables, Db, ExtCtrls, StdCtrls;

    >

    > type

    > TForm1 = class(TForm)

    > MNAME: TEdit;

    > MCOMPANY: TEdit;

    > LBIName: TListBox;

    > Panel1: TPanel;

    > Panel2: TPanel;

    > QTransaction: TQuery;

    > Database1: TDatabase;

    > procedure MNAMEKeyPress(Sender: TObject; var Key: Char);

    > private

    > { Private declarations }

    > public

    > { Public declarations }

    > end;

    >

    > var

    > Form1: TForm1;

    >

    > implementation

    >

    > {$R *.DFM}

    >

    > procedure TForm1.MNAMEKeyPress(Sender: TObject; var Key: Char);

    > var

    > i:Byte;

    > m_MName:String;

    > begin

    > if Key=#13 then

    > begin

    > if MNAME.Text='' then

    > Exit;

    > With QTransaction do

    > Begin

    > SQL.BeginUpdate;

    > SQL.Clear;

    > SQL.Add('SELECT Name,Company');

    > SQL.Add(' FROM CHECK');

    > SQL.Add(' WHERE Name LIKE :MNAME');

    > SQL.EndUpdate;

    > ParamByName('Name').AsString:=MNAME.Text+'%';

    > Open;

    > if RecordCount = 0 then

    > begin

    > Exit;

    > end else

    > begin

    > Key :=#0;

    > LBIName.Items.Beginupdate;

    > LBIName.Items.Clear;

    > while not EOF do

    >

    > Begin

    > m_MName := FindField('Name').AsString;

    > for i:= 1 to - length(m_MName)do

    > m_MName := m_MName+'';

    > LBIName.Items.Add(m_MName+'-'+

    > FindField('Company').AsString);

    > Next;

    > end;

    > LBIName.Items.EndUpdate;

    > LBIName.ItemIndex := 0;

    > if LBIName.Items.Count = 1 then

    > begin

    > SendMessage(LBIName.Handle,WM_CHAR,13,0);

    > end else

    > begin

    > LBIName.Height :=100;

    > LBIName.BringToFront;

    > LBIName.Visible := True;

    > LBIName.SetFocus;

    > end;

    > end;

    > end;

    > end;

    >

    > end;

    >

    > end.

    > 입니다.. 고수님들의 많은 협조 부탁 드립니다...

    > 흠..

    > 참고

    > LBIName은 리스트 박스구...

    > MNAME은 Edit1이구..

    > MCOMPANY는 Edit2이구

    > Table name ; check

    > field Name,Company입니다..

    > 그럼 좋은 조언 기다리겠습니다..

    >