?
Solved

ADOQuery

Posted on 2003-03-10
7
Medium Priority
?
426 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
[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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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