Failed to make a change to the database

0

When I make a Update in the Impressora table my program is closing itself, when debugging the program the following error was accused:

MyUpdatelookslikethis:

beginifcdsImpressora.statein[dsedit]thenbegindmDatabase.SQLConnection.Execute('UPDATEImpressorasSET'+'PATRIMONIO='''+cdsImpressoraPATRIMONIO.AsString+''','+'PATRIMONIOBANDEJA='''+cdsImpressoraPATRIMONIO.AsString+''','+'PATRIMONIODUPLEX='''+cdsImpressoraPATRIMONIODUPLEX.AsString+''','+'PATRIMONIOMAILBOX='''+cdsImpressoraPATRIMONIOMAILBOX.AsString+''','+'NUMEROIP='''+cdsImpressoraNUMEROIP.AsString+''','+'ENDERECOEXTERNO='''+cdsImpressoraENDERECOEXTERNO.AsString+''','+'NUMERONF='''+cdsImpressoraNUMERONF.AsString+''','+'NUMEROPORTA='''+cdsImpressoraNUMEROPORTA.AsString+''','+'NUMEROSERIE='''+cdsImpressoraNUMEROSERIE.AsString+''','+'SENHA='''+cdsImpressoraSENHA.AsString+''','+'USUARIO='''+cdsImpressoraUSUARIO.AsString+''','+'CAMINHO='''+cdsImpressoraCAMINHO.AsString+''','+'SETORINSTALACAO='''+cdsImpressoraSETORINSTALACAO.AsString+''','+'CODIGOMODELO='+cdsImpressoraCODIGOMODELO.AsString+','+'FRANQUIA='+iif(cdsImpressoraFRANQUIA.AsString='','0',cdsImpressoraFRANQUIA.AsString)+','+'VALORIMPRESSAO='+iif(cdsImpressoraVALORIMPRESSAO.AsString='','0',TrocaVirgPPto(cdsImpressoraVALORIMPRESSAO.AsString))+','+'TIPOPATRIMONIO='''+cdsImpressoraTIPOPATRIMONIO.AsString+''','+'PATRIMONIOOUTRO='''+cdsImpressoraPATRIMONIOOUTRO.AsString+''','+'VALORIMPRESSAOCOLOR='+iif(cdsImpressoraVALORIMPRESSAOCOLOR.AsString='','0',TrocaVirgPPto(cdsImpressoraVALORIMPRESSAOCOLOR.AsString))+','+'FRANQUIACOLOR='+iif(cdsImpressoraFRANQUIACOLOR.AsString='','0',cdsImpressoraFRANQUIACOLOR.AsString)+','+'CORTESIAIMPRESSAO='+iif(cdsImpressoraCORTESIAIMPRESSAO.AsString='','0',cdsImpressoraCORTESIAIMPRESSAO.AsString)+','+'VALOREXCEDENTEIMPRESSAOCOLOR='+iif(cdsImpressoraVALOREXCEDENTEIMPRESSAOCOLOR.AsString='','0',TrocaVirgPPto(cdsImpressoraVALOREXCEDENTEIMPRESSAOCOLOR.AsString))+','+'VALORFIXOMENSAL='+iif(cdsImpressoraVALORFIXOMENSAL.AsString='','0',TrocaVirgPPto(cdsImpressoraVALORFIXOMENSAL.AsString))+','+'VALOREXCEDENTEDIGITALIZACAO='+iif(cdsImpressoraVALOREXCEDENTEDIGITALIZACAO.AsString='','0',TrocaVirgPPto(cdsImpressoraVALOREXCEDENTEDIGITALIZACAO.AsString))+','+'VALORDIGITALIZACAO='+iif(cdsImpressoraVALORDIGITALIZACAO.AsString='','0',TrocaVirgPPto(cdsImpressoraVALORDIGITALIZACAO.AsString))+','+'STATUS='+QuotedStr(cdsImpressorastatus.AsString)+','+'FRANQUIADIGITALIZACAO='+iif(cdsImpressoraFRANQUIADIGITALIZACAO.AsString='','0',TrocaVirgPPto(cdsImpressoraFRANQUIADIGITALIZACAO.AsString))+'whereCODIGO='+cdsImpressoraCODIGO.AsString,nil);end;end;cdsImpressora.Close;sdsImpressora.CommandText:='select*fromImpressoraswherecodigo=0';cdsImpressora.Open;MostraFila(0);

Andmyimpressoratableissetupasfollows:

If you have any idea what might be happening. Because to insert in the database the error does not occur.

    
asked by anonymous 13.01.2017 / 11:59

2 answers

2

Your CODIGOMODELO is a integer in the database and in your update you are not doing IIF

' CODIGOMODELO = ' +iif(cdsImpressoraCODIGOMODELO.AsString='','0',cdsImpressoraCODIGOMODELO.AsString)+','+

One thing you can do to help you identify problems. Is separating your sql statement into a variable, and using the delphi debug mode, evaluating the value of the variable to identify possible concatenation problems.

One of the ways to inspect is in debug mode you hit the Ctrl+F7 string and use Evaluate/Modify to see the value of the variable.

In the image I'm inspecting my variable update , being able to copy the text that is in result and analyze it better using some database tool.

    
13.01.2017 / 14:20
0

Make a match between bank and your update so that you can identify which field is causing the conversion error.

A technique I use in this case is to take a piece of the update and leave a few fields and add the others gradually, this way you will see which field is giving the problem.

    
05.02.2017 / 15:07