-1
try
DModuleGrid.ZQuery1.Close;
DModuleGrid.ZQuery1.SQL.Clear;
DModuleGrid.ZQuery1.SQL.Add('SELECT * FROM tdcupant');
DModuleGrid.ZQuery1.SQL.Add('WHERE numcupom = :co2 AND ccf = :cc3 AND dtcompra = :dtc4 AND impcaixa = :ip5');
DModuleGrid.ZQuery1.ParamByName('co2').AsString := copy(lTemp,53,6);
DModuleGrid.ZQuery1.ParamByName('cc3').AsString := copy(lTemp,47,6);
DModuleGrid.ZQuery1.ParamByName('ip5').AsString := copy(lTemp,4,20);
DModuleGrid.ZQuery1.ParamByName('dtc4').AsDate := StrToDate(dtcompratxt);
DModuleGrid.ZQuery1.Open;
except
on e: Exception do
begin
ercp := e.Message;
StatusBar1.Panels[0].Text := 'Erro ao encontrar registros! ' + ercp;
end;
I believe it is right. But it keeps indicating the error of the own sql
.
Well, the mistake is:
To be precise, it only needs to capture an exception in case none of the records I compared in the parameters are found in the database.
Which error? tested the direct query in the bank?
– rray
@Yes, the query presented there, is that you need to have the records registered in the database to match the parameters, however, obviously it is not all file . txt that there are the correct records that is in the database, the error is
Sql Sintaxe
, which is when you don’t find any records, after you go through the entire database and the txt file.– Ramon Ruan
@lost, but that’s exactly what I’m doing, causing error selecting a wrong file, for me to treat it, but it’s not treating.
– Ramon Ruan
@Ramonruan Exception when performing the open does not mean that it has not encoded records. A syntax error is when your query is misspelled. Transcribe the error so that it is easier to help. And if you treat
on e: Exception
means every kind of exception and therefore will never fall into yourelse
. If what you want is to throw an exception if you don’t find records, that’s another thing– Caputo
@Caputo, follow up on the error image. The Else, it was just a little test, as I am re-learning the language, there is a lot that I missed and lack to learn. haha
– Ramon Ruan
It will not be the lack of a space between
SELECT * FROM tdcupant
andWHERE...
?– Jorge B.
@Jorgeb. I think not, because they are in different lines when they are added. But only for testing, I did, but this is how it appears.
– Ramon Ruan
Experiment for a space before
WHERE
. It’s usually most of my SQL problems.– Jorge B.
Before the
DModuleGrid.ZQuery1.Open
gives aShowmessage(DModuleGrid.ZQuery1.SQL.Text)
and say what comes, please.– Filipe.Fonseca
@Filipe.Fonseca
SELECT * FROM tdcupant WHERE numcupom = :co2 AND ccf = :cc3 AND dtcompra = :dtc4 AND impcaixa = :ip5
, this message, withsql
.– Ramon Ruan
I was going to post as a comment, but it got big d+, so it was as a response. If it does not work edit later.
– Filipe.Fonseca
@Fonseca, I was looking at my code, and I debuggged in another corner, I put a point for every while and if beginning existing in that procedure, and I found a line where, "if I didn’t find any record it would give a value=''..." sql accepts nothing in the field but a 0. I will post the answer right now.
– Ramon Ruan