?
Solved

Database lookup method

Posted on 2003-03-20
6
Medium Priority
?
284 Views
Last Modified: 2010-04-03
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
Comment
Question by:rpm_bmbz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:rpm_bmbz
ID: 8177616
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8179191
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
 

Author Comment

by:rpm_bmbz
ID: 8213598
Is there a way to do it with a DBisam Query instead of ADO?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rpm_bmbz
ID: 8213738
Is there a way to do it with a DBisam Query instead of ADO?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 1600 total points
ID: 8213794
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8229792
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question