Solved

check if record exists

Posted on 2007-03-20
3
599 Views
Last Modified: 2012-06-27
I use a lookupcombo to get 'list_number' info. from a table.
I also have my contacts showing (name,surname)
in a grid (that gets data from a queery)..
So before I do anything I would like to check if a list_number allready exists
for the selected contact in the grid.
(a check would be on the exit event of the lookupcombo using a queery just for that purpose)
0
Comment
Question by:Vrtnar
3 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 18758858
If using ADO and an ADOTable try:

if ADOTable1.Locate('FieldName', MyLookupValue', [loCaseInsensitive]) then
 begin
 // Do something...
 end;

An ADOQuery is identical.

An SQL Query would be:

var
 MyString : String;

MyTable.Close;
MyTable.SQL.Clear;
MyTable.SQL.Add('Select SomeField where my FieldName = 'MyLookupValue'
MyTable.Open;

if MyString := MyTable.FieldByName('SomeField').AsString;
 begin

 end

Is this what you are after?

JJ

0
 

Author Comment

by:Vrtnar
ID: 18762262
No...anyway the rigt way would be this (ado) :
With ADOQuery1 do begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text := 'SELECT myfield FROM mytable WHERE myfield= ' + QuotedStr(dblookupcombo1.Text);
adoQuery1.Open;
if EOF then abort
else
ShowMessage('Value '+dblookupcombo1.Text+' allready exists!');
end;
...however I must check selected record also from the grid..
How do you search selected record in the grid?
0
 
LVL 22

Accepted Solution

by:
senad earned 125 total points
ID: 18762592
something like this :
With Query do begin //new queery
close;
Query.SQL.Clear;
if Query.FieldByName('whatever').AsString <> '' then  //this queery shows contacts
begin
SQL.Text:= 'select whatever from mytable  where whatever = ' + Query.FieldByName('wharever').AsString + ' AND whatever = ' + QuotedStr(dbLookupcombo.Text);
Query.Open;
if EOF then abort
else
ShowMessage('exists allready');
end;
end;
end;
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now