Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

check if record exists

Posted on 2007-03-20
3
Medium Priority
?
612 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
[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 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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
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

636 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