?
Solved

ADOQuery

Posted on 2003-03-10
7
Medium Priority
?
437 Views
Last Modified: 2010-08-05
hi
i have a form and i'm connect to a SQL database , i wanna write a Query and i use this way :
  ADOQuery1.Close;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('select name from personel');
  ADOQuery1.SQL.Add('where id="'+edit1.text+'" ');
  ADOQuery1.Open;
but it doesnt work , i receive an error that: " invalid column name '5133' "
my edit1.text is 5133 and there is it in my table but i dont know why i receive this error
plz help me  
0
Comment
Question by:Mahsa60
7 Comments
 
LVL 9

Accepted Solution

by:
mocarts earned 200 total points
ID: 8102134
what type is field ID in your database
if numeric then use

ADOQuery1.SQL.Text := 'SELECT name FROM personel WHERE id='+ Edit1.Text;  // assigning SQL closes Query
ADOQuery1.Open;

if character type then
ADOQuery1.SQL.Text := 'SELECT name FROM personel WHERE id='+ QuotedStr(Edit1.Text);  // assigning SQL closes Query
ADOQuery1.Open;

wbr, mo.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8102149
try it in this way

ADOQuery1.SQL.Add('select name from personel');
ADOQuery1.SQL.Add('where id='+edit1.text+' ');
 
better would be to use paramaters like

ADOQuery1.SQL.Add('select name from personel');
ADOQuery1.SQL.Add('where id=:ID ');
ADOQuery1.ParamByName('ID').AsInteger := IntToStr(Edit1.Text);
...  not tested

meikl ;-)
0
 
LVL 9

Expert Comment

by:mocarts
ID: 8102174
with ADO there is some incompatibility with other data access components :(

to use parameters you must do like this:

ADOQuery1.SQL.Text := 'SELECT name FROM personel WHERE id=:ID';
ADOQuery1.Parameters.ParamByName('ID').AsInteger := StrToInt(Edit1.Text);

wbr, mo.
0
Technology Partners: 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!

 

Expert Comment

by:Imbeginner
ID: 8106935
hi mahsa60
try it in this way:

with adoquery1 do
begin
 CONNECTION:=ADOCONNECTION1;
 SQL.clear;
 SQL.add(format('select name from article where ID="%s"',[edit1.text]));
 open;
end;


best regards
m.reza
0
 

Expert Comment

by:Imbeginner
ID: 8106976
sorry mahsa60,
I test above comment in my database, the correct syntax for your database is :


with adoquery1 do
begin
 SQL.clear;
 SQL.add(format('select name from personal where ID="% s"',[edit1.text]));
open;
end;



m.reza
0
 

Author Comment

by:Mahsa60
ID: 8109203
tanx to u all
0
 

Expert Comment

by:hetturki
ID: 8110402
if the type off ID is string do as following

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select name from personel');
ADOQuery1.SQL.Add('where ID = :xvar');
ADOQuery1.parameters.parabyname('xvar').value := edit1.text;
ADOQuery1.SQL.open;

if not an string change edit1.text the equivelent type
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

609 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