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
Solved

check if record exists

Posted on 2007-03-20
3
604 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 Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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