?
Solved

check if record exists

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 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