Failed to make a database change

Asked

Viewed 78 times

0

When I’m gonna make a Update on the table Impressora my program is closing itself, while debugging the program the following error has been accused:

inserir a descrição da imagem aqui

My Update is this way:

begin
    if cdsImpressora.state in[dsedit] then
    begin
      dmDatabase.SQLConnection.Execute('UPDATE Impressoras SET '+
         ' 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))+
         ' where CODIGO = '+cdsImpressoraCODIGO.AsString, nil);
    end;
  end;
  cdsImpressora.Close;
  sdsImpressora.CommandText := 'select * from Impressoras where codigo = 0' ;
  cdsImpressora.Open;
  MostraFila(0);

And my table impressora is configured as follows:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

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

  • 2

    Most likely one of your entire fields is empty. And I see that you have not yet learned to use Quotedstr.

2 answers

2


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

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

Something you can do to help you identify problems. Is to separate your sql statement into a variable, and using Delphi’s debug mode, evaluate the value of the variable to identify possible concatenation problems.

One of the ways to inspect is in debug mode you tighten the sequence Ctrl+F7 and use the Evaluate/Modify to see the variable value.inserir a descrição da imagem aqui

In the picture I’m inspecting my variable update, can copy the text in result and analyze better using some database tool.

  • I must use iff if it’s Integer at the bank? I’m sorry the question is that I’m a beginner in Delphi and this code wasn’t developed by me

  • Say yes, whenever the field is integer, you have to assemble the instruction by passing an integer and how you are using an Asstring, if the field value is nil Delphi leaves your concatenation blank. But your programming style is far outside of the development standards that Delphi provides, I would advise you to use the palette components Data Controls together with those of Data Access and their DataSets. By joining these components, you don’t need to digest a line of code if you want to make a simple CRUD.

  • Another thing, if you’re starting with Delphi, why Delphi? I particularly no longer start any project in Delphi, my new projects are all in C#.

  • Yes, actually I suggested that it be updated to Java which is a language that I have more domain but I was instructed to only make the necessary changes to Debian anyway

  • I made that change that you suggested in your reply, but the same mistake kept occurring

  • I made an edit on the reply

Show 2 more comments

0

Do a theparam between database and your update so you can identify which field is causing the conversion error.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.