Help! Login program can't check the credentials! lazarus / 16-Databases ---------------------------------------------------------------------- workinghard · 2012-04-29 08:53 So i was making a login program (using only 1 parameter, which is the address) and for reasons that i don't know, it can't do anything except telling me that the address is not found Code: [Select]begin      qcalc.Close;      qcalc.sql.clear;      qcalc.sql.add('SELECT * FROM Master WHERE master.address='+QuotedStr(Address.Text));     if Qcalc.recordcount = 0 then     begin     showmessage('Address not found');     end  Where did i mess up? In the master table there are already lots of addressess, and each one of them doesn't work when tested ---------------------------------------------------------------------- BigChimp · 2012-04-29 09:43 Start reading some documentation as lots of us already asked you to do. Try to look up the answer to some question: How do you execute a query? Why is it a bad idea to use QuotedStr unless you REALLY know what you're doing? (Hint: parameters, entering Jim's 12" Steak Knife as data, or perhaps "The Willows", 12 O'Malley Drive, Maplewood) Good luck ---------------------------------------------------------------------- workinghard · 2012-04-29 23:09 Following your advice, i changed the code to this: Code: [Select]     qcalc.Close;      qcalc.sql.clear;      qcalc.sql.add('SELECT * FROM Master WHERE master.address:=Address');      qcalc.Params.ParamByName('Address').AsString := Address.text; When I ran the program again, i got the error saying parameter Address not found... this error has been present for quite a while now... ---------------------------------------------------------------------- goldenfox · 2012-04-30 03:33 it should be something like Quoteqcalc.sql.add('SELECT * FROM Master WHERE master.address=:Address'); qcalc.Params.ParamByName('Address').AsString := Address.text; Notice the bold =: ---------------------------------------------------------------------- workinghard · 2012-04-30 09:08 Quote from: goldenfox on April 30, 2012, 05:33:33 amit should be something like Quoteqcalc.sql.add('SELECT * FROM Master WHERE master.address=:Address'); qcalc.Params.ParamByName('Address').AsString := Address.text; Notice the bold =: I've tried it man, it doesn't work The code is now: Code: [Select]begin      qcalc.Close;      qcalc.sql.clear;      qcalc.sql.add('SELECT * FROM master WHERE address=:Address');      qcalc.Params.ParamByName('Address').AsString := Address.text;     if QHitung1.recordcount = 0 then     begin     showmessage('Address not found!');     end ---------------------------------------------------------------------- Arbee · 2012-04-30 09:12 Is this the complete code? I do not see you executing the SQL statement anywhere (via an "open"). ---------------------------------------------------------------------- joseme · 2012-04-30 09:14 You should open the query after passing the parameter, the code should be something like Code: [Select]begin      qcalc.Close;      qcalc.sql.clear;      qcalc.sql.add('SELECT * FROM master WHERE address=:Address');      qcalc.Params.ParamByName('Address').AsString := Address.text;      qcalc.open;     if qcalc.recordcount = 0 then     begin     showmessage('Address not found!');     end ---------------------------------------------------------------------- workinghard · 2012-04-30 09:24 Following Joseme's advice i've added the qcalc.open code. And now the code goes like this Code: [Select]begin      qcalc.Close;      qcalc.sql.clear;      qcalc.sql.add('SELECT * FROM master WHERE address=:Address');      qcalc.Params.ParamByName('Address').AsString := Address.text;      qcalc.open;     if qcalc.recordcount = 0 then     begin     showmessage('Address not found!');     end      else     begin       Qcalc.Close;       Qcalc.sql.clear;       Qcalc.sql.text:='INSERT INTO trmt VALUES (address.text), CURRENT_TIMESTAMP, 20000, ( SELECT (M.land*RM.landrate)+(M.bldg*RM.bldgrate) FROM MASTER AS M, Rmnt AS RM WHERE M.Address := address AND M.Cluster = RM.Cluster)';       QHitung1.execSQL;       TransHitung.commit;       Qcalc.sql.clear;       Qcalc.sql.text:=' INSERT INTO trair VALUES (edAddress), CURRENT_TIMESTAMP,( SELECT M.PemAirTrkr FROM MASTER AS M WHERE M.Address:=EdAddress), edMTA, (BAw-BAk)';       Qcalc.execSQL;       Transcalc.commit;       Qcalc.sql.clear;       Qcalc.sql.text:='UPDATE master SET PemAirTrkr = edMTA WHERE Alamat = EdAddress';       Qcalc.ExecSQL;       Transcalc.Commit;     end; end;                      It still raises the same old error Do i mess up somewhere else? ---------------------------------------------------------------------- joseme · 2012-04-30 10:05 This is very strange, your code is correct. Can you run this simple code? Code: [Select]qCalc.close; qCalc.Text := 'select * from master'; qCalc.open; showMessage(qCalc.fieldbyname('Address').Asstring)It should show you the first address in the table. ---------------------------------------------------------------------- workinghard · 2012-04-30 10:57 I do this: Code: [Select]procedure TForm3.Button1Click(Sender: TObject); begin   qcalc.close;   qcalc.clear;   qcalc.add := 'SELECT * FROM Master';   qcalc.open;   showmessage(qcalc.fieldbyname('address').asstring) ; end; And I get this error: Quoteunit3.pas(58,12) Error: identifier idents no member "clear" unit3.pas(59,12) Error: identifier idents no member "add" unit3.pas(62,22) Error: Identifier not found "qcalc" unit3.pas(67) Fatal: There were 3 errors compiling module, stopping And using this syntax: Code: [Select]qCalc.close; qCalc.Text := 'select * from master'; qCalc.open; showMessage(qCalc.fieldbyname('Address').Asstring) I have this error: Quoteunit3.pas(58,12) Error: identifier idents no member "text" unit3.pas(61,22) Error: Identifier not found "qcalc" unit3.pas(66) Fatal: There were 2 errors compiling module, stopping Oh, and by using this: Code: [Select]begin   qcalc.sql.close;   qcalc.sql.text := 'SELECT * FROM Master';   qcalc.sql.open;   showmessage(qhitung.fieldbyname('address').asstring) ; end; This showed up: Quoteunit3.pas(57,16) Error: identifier idents no member "close" unit3.pas(59,16) Error: identifier idents no member "open" unit3.pas(61,22) Error: Identifier not found "qcalc" unit3.pas(66) Fatal: There were 3 errors compiling module, stopping Is there anything wrong with my SQL library then? I use Lazarus 0.9.30.4 with FPC 2.6.0 in Win7 Home Premium x64 Also I installed it in drive D, since the drive C has the older version and I still need it... ---------------------------------------------------------------------- workinghard · 2012-05-01 15:55 please, anyone? ---------------------------------------------------------------------- dr4cul453xy · 2012-05-16 09:00 Quote from: workinghard on April 30, 2012, 12:57:47 pmI do this: Code: [Select]procedure TForm3.Button1Click(Sender: TObject); begin   qcalc.close;   qcalc.clear;  // <<<<< THIS ONE   qcalc.add := 'SELECT * FROM Master'; // <<<<< and THIS ONE   qcalc.open;   showmessage(qcalc.fieldbyname('address').asstring) ; end; I think you  messed up something (the marked part). the debugger has already told you what to do it should be as follow : Code: [Select]  qcalc.close;   qcalc.SQL.clear;  // <<<<< CHANGE TO THIS ONE   qcalc.SQL.add := 'SELECT * FROM Master'; // <<<<< CHANGE TO THIS ONE   qcalc.open; please let me know if it still raising error..