Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Database lookup method

I cant get the lookup method to work in Delphi 7.
If any one could send me some sample code I would be extremly grateful.
The database I am serching is "DataModuleForm.LoadTable" and I'm searching the "PO_NUM" field.

Thanks
Rory
0
rpm_bmbz
Asked:
rpm_bmbz
  • 3
  • 3
1 Solution
 
rpm_bmbzAuthor Commented:
Is what I'm trying to do is an error check, I dont want the same P.O. Number twice, and if I use "locate" it screws the editing form.

0
 
kretzschmarCommented:
i would solve it in another way, like

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB;

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    ADOQuery1: TADOQuery;
    procedure ADOTable1BeforePost(DataSet: TDataSet);
  private
    Function value_exists(AValue : String) : Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
//checkFunction
Function TForm1.value_exists(AValue : String) : Boolean;
const
  ASQL = 'Select 1 from Test where Text = %s';
begin
  adoquery1.Close;
  adoquery1.SQL.Text := Format(ASQL,[QuotedStr(AValue)]);
  adoquery1.Open;
  result := not adoquery1.IsEmpty;
  adoquery1.Close;
end;

procedure TForm1.ADOTable1BeforePost(DataSet: TDataSet);
begin
  if adotable1.State = dsInsert then
    if value_exists(adotable1.FieldByname('Text').AsString) then
      raise exception.Create('Value in Field Text already exists!');
end;

end.

btw. usual i create a unique index on this column,
where i don't wnat duplicate entries,
to let check the database, rather than my app

meikl ;-)
0
 
rpm_bmbzAuthor Commented:
Is there a way to do it with a DBisam Query instead of ADO?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rpm_bmbzAuthor Commented:
Is there a way to do it with a DBisam Query instead of ADO?
0
 
kretzschmarCommented:
don't know what you mean with dbIsamQuery,
but for this it is not a must to use ado,
same would also work with the bde or some other
thirdparty-products i know

meikl ;-)
0
 
kretzschmarCommented:
go here

http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

read there the paragraph
How Do I Know What Grade to Give?

and explain why you give a c-grade

meikl ;-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now