0

hi im working on delphi 10 and sybase.

Im having this issue 2 days ago and i've tried a lot of things. i set the adoconnection properties in build, searh my db and its ready. I can insert,delete and update but when im trying to make a select x from y where z the output is COLUMN Y NOT FOUND

when i do a :

select * from administradores 

it work,but the one i need dont. My code is this one.

ADOQuery1.Close ;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='SELECT usu_administrador,pass_administrador from administradores  where usu_administrador='+Edit1.Text+'';
ADOQuery1.Open;

i already tried SQL syntax error ,open fields editor and it dont even have fields. That post it exactly what happen to me, but that solution didnt work for me.

Please,could someone help me?

Community
  • 1
  • 1
Jose Valverde
  • 19
  • 1
  • 3
  • 9
  • `SQL.Clear` is not needed before `SQL.Text :=...` since `SQL.Clear` only makes sense before `SQL.Add(...)` /// the stile is very fragile - as soon as user puts a quote into Edit1 your program is screwed: http://bobby-tables.com/delphi.html – Arioch 'The Jan 31 '14 at 18:20
  • in this moment try both and they have the same output... Column y not found!... I insist... it exist! :S – Jose Valverde Jan 31 '14 at 18:23
  • What is Delphi 10? Delphi 2006 ? // edit the question and copy FULL and EXACT text of the error (1) // ensure the query is totally empty - no Fields, not FieldDefs, no IndexDefs, no IndexFieldNames and so on. http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/!!MEMBEROVERVIEW_ADODB_TADOQuery.html // Actually it would be good if you would post here your ADOQuery1 sources (2) from DFM (google "view dfm as text") after the exact text of error. Also seeing the SQL declaration of the table (3) would also be good. So, waiting for (1),(2),(3) – Arioch 'The Jan 31 '14 at 18:26
  • hi, i already fix it with the answer below! just made this ADOQuery1.SQL.Text:='SELECT usu_administrador,pass_administrador from administradores where usu_administrador='+QuotedStr(Edit1.Text); Thanks for your attention :) – Jose Valverde Jan 31 '14 at 18:29
  • I see, and trust us both - it is a BAD pseudo-solution. We both told you instantly - do use parameters – Arioch 'The Jan 31 '14 at 18:31
  • Also, what is the point in `SELECT usu_administrador` if usu_administrator you read from Edit1 ??? – Arioch 'The Jan 31 '14 at 18:31
  • yes! i already make it with parameters. The final code is this one. Thanks to all. ADOQuery1.Close ; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Text:='SELECT usu_administrador,pass_administrador from administradores where usu_administrador= :nombre'; ADOQuery1.Parameters.ParamByName('nombre').Value := Edit1.Text; ADOQuery1.Open; – Jose Valverde Jan 31 '14 at 18:36
  • I repeat: you do not need sql.clear here, does nothing. And why fetching the 1st field if you set it being equal to edit1? just read edit1 instead – Arioch 'The Jan 31 '14 at 19:34

1 Answers1

1

You should really use parameters in your queries

ADOQuery1.SQL.Text:='SELECT usu_administrador, pass_administrador ' +
      ' from administradores  where usu_administrador = :paramadminname';
ADOQuery1.ParamByName('paramadminname').Value := Edit1.Text;

Also, the reason why your query didn't work was that the value in Edit1 must be in quotes for it to work in your SQL

ADOQuery1.SQL.Text:='SELECT usu_administrador,pass_administrador from administradores  where usu_administrador='+QuotedStr(Edit1.Text);
Arioch 'The
  • 15,799
  • 35
  • 62