Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > MS SQL Server
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 03-11-2022
Avatar de kuan-yiu
[kuan-yiu] kuan-yiu is offline
Miembro Premium
 
Registrado: jun 2006
Ubicación: Galicia. España.
Posts: 1.017
Poder: 19
kuan-yiu Va camino a la fama
Comillas.
Código Delphi [-]
ADOQueryUpdate.SQL.Add( 'Estatus = 'OLD');
Código Delphi [-]
ADOQueryUpdate.SQL.Add( 'Estatus = "OLD" ');
ADOQueryUpdate.SQL.Add( 'Estatus = ' +QuotedStr('OLD'));
Y de paso parametriza, que siempre es buena idea:
Código Delphi [-]
ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
 ParamByName('valor').AsString := Trim(Label3.Caption);
Responder Con Cita
  #2  
Antiguo 03-11-2022
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.107
Poder: 34
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola a todos,

Cita:
Empezado por kuan-yiu Ver Mensaje
Y de paso parametriza, que siempre es buena idea:
Código Delphi [-]
ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
 ParamByName('valor').AsString := Trim(Label3.Caption);
¡Haz caso a quien sabe!
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita
  #3  
Antiguo 03-11-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
Cita:
Empezado por kuan-yiu Ver Mensaje
Comillas.
Código Delphi [-]
ADOQueryUpdate.SQL.Add( 'Estatus = 'OLD');
Código Delphi [-]
ADOQueryUpdate.SQL.Add( 'Estatus = "OLD" ');
ADOQueryUpdate.SQL.Add( 'Estatus = ' +QuotedStr('OLD'));
Y de paso parametriza, que siempre es buena idea:
Código Delphi [-]
ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
 ParamByName('valor').AsString := Trim(Label3.Caption);
Gracias por responder amigo:
Aun no me rindo, pero aun tampoco tengo la solucion colocando el codigo tal cual tu mencionaste me da un erro que lo voy a adjuntar

Código:
begin
        Close;
        ADOQueryUpdate.SQL.Clear;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket SET');
        ADOQueryUpdate.SQL.Add( 'Estatus = "OLD" ');
        ADOQueryUpdate.SQL.Add( 'Estatus = ' +QuotedStr('OLD'));
        ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
        ADOQueryUpdate.Parameters.ParamByName('Valor').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.ExecSQL;
        end;
Hay una cosa que no entiendo del código y talvez alli el error
Código Delphi [-]
ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
yo no temg ningún campo o resultado que se llame 'valor', por lo que puedo asumir que este 'valor' sea una constante que abajo se le esta pasando el valor contenido en el Label3.caption, y de ser asi en el futuro tengo que hacer lo mismo con cada campo a la cual le voy a pasar el valor de un label?

Yo no se y quiero entender como una instrucion tan simple el SQL
Código SQL [-]
 Update Tiket set Estatus = 'NEW' Where Item = '2'
donde solo quiero cambiar el valor que esta en el 2 y colocarle un valor contenido en un label se ha convertido en un problema

Última edición por giantonti1801 fecha: 29-03-2023 a las 20:43:36.
Responder Con Cita
  #4  
Antiguo 03-11-2022
Avatar de kuan-yiu
[kuan-yiu] kuan-yiu is offline
Miembro Premium
 
Registrado: jun 2006
Ubicación: Galicia. España.
Posts: 1.017
Poder: 19
kuan-yiu Va camino a la fama
Puse dos opciones para la misma linea, jeje, no tienes que usar las dos, sino la que prefieras: con comillas o con QuotedStr (que es la que a mi me gusta más).
Por eso te da error, piensa que son dos campos y espera una coma en medio.
Responder Con Cita
  #5  
Antiguo 03-11-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
Cita:
Empezado por kuan-yiu Ver Mensaje
Puse dos opciones para la misma linea, jeje, no tienes que usar las dos, sino la que prefieras: con comillas o con QuotedStr (que es la que a mi me gusta más).
Por eso te da error, piensa que son dos campos y espera una coma en medio.

Si puedo entender eso pero a cual te refiere, talvez seria de ayuda si escribiera el codigo tal cual como deberia ir.

Muchas gracias por tu ayuda
Responder Con Cita
  #6  
Antiguo 03-11-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
Cita:
Empezado por giantonti1801 Ver Mensaje
Si puedo entender eso pero a cual te refiere, talvez seria de ayuda si escribiera el codigo tal cual como deberia ir.

Muchas gracias por tu ayuda
Listo, ya con tu ayuda pude resolver el problema, muchissimas gracias....

Código Delphi [-]
begin
        Close;
        ADOQueryUpdate.SQL.Clear;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket SET');
        ADOQueryUpdate.SQL.Add( 'Estatus = ' +QuotedStr('OLD'));
        ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
        ADOQueryUpdate.Parameters.ParamByName('Valor').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.ExecSQL;
        end;

Para ayudar a otros foreros que tengan el mismo problema el codigo quedo Asi.
Responder Con Cita
  #7  
Antiguo 03-11-2022
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
Cita:
Empezado por giantonti1801 Ver Mensaje
Listo, ya con tu ayuda pude resolver el problema, muchissimas gracias....

Código Delphi [-]
begin
        Close;
        ADOQueryUpdate.SQL.Clear;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket SET');
        ADOQueryUpdate.SQL.Add( 'Estatus = ' +QuotedStr('OLD'));
        ADOQueryUpdate.SQL.Add(' WHERE Item =:valor');
        ADOQueryUpdate.Parameters.ParamByName('Valor').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.ExecSQL;
        end;

Para ayudar a otros foreros que tengan el mismo problema el codigo quedo Asi.
Pueden indicarme como hacer ahora para agregar mas informacion? es decir tengo que dentro del mismo update cambiar otros campos que estan igual en otro label
Responder Con Cita
  #8  
Antiguo 03-11-2022
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.055
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Código SQL [-]
update tabla1 set campo1=aaa, campo2=bbb, campo3=ccc where...
Responder Con Cita
  #9  
Antiguo 03-11-2022
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 914
Poder: 23
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Cita:
Empezado por giantonti1801 Ver Mensaje
Pueden indicarme como hacer ahora para agregar mas informacion? es decir tengo que dentro del mismo update cambiar otros campos que estan igual en otro label
Me tomé la libertad de usar el mismo código del colega giantonti1801, he incorporé otros atributos...

En mi opinión y por claridad, los parametros deberian tener el mismo nombre de los campos a actualizar. Por supuesto eso queda a criterio y gusto del colega...

Código Delphi [-]
        
        Close;
        ADOQueryUpdate.SQL.Clear;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket'
        ADOQueryUpdate.SQL.Add( 'SET ');
    ADOQueryUpdate.SQL.Add( 'Estatus =:Estatus,');
    ADOQueryUpdate.SQL.Add( 'Nombre  =:Nombre,');
    ADOQueryUpdate.SQL.Add( 'Apellido=:Apellido,');
    ADOQueryUpdate.SQL.Add( 'Edad    =:Edad');
    ADOQueryUpdate.SQL.Add(' WHERE Item =:Item');
    
        //Asignación de valores a los parametros...  
    //Precaución con los tipos de datos
    ADOQueryUpdate.Parameters.ParamByName('Estatus').Value :='OLD';
    ADOQueryUpdate.Parameters.ParamByName('Nombre').Value  :='Merluso';
    ADOQueryUpdate.Parameters.ParamByName('Apellido').Value:='Boric';
    ADOQueryUpdate.Parameters.ParamByName('Edad').Value    :=19;
        ADOQueryUpdate.Parameters.ParamByName('Item').Value    := StrToInt(Label3.Caption);
        ADOQueryUpdate.ExecSQL;
        end;

Saludos cordiales
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Cambiar el caption de un Label(LinkLabel, etc) en tiempo de ejecución Missael Delphi para la web 2 19-09-2018 23:14:24
label.caption en 2 renglones ingel Varios 5 16-04-2018 23:13:32
No cambia caption el label giulichajari Varios 2 07-07-2015 05:08:29
Caption de Label en varias filas Novatin C++ Builder 6 03-07-2013 05:24:52
Pierdo datos de memo.text a label.caption jgarcias2 OOP 7 18-04-2011 19:27:45


La franja horaria es GMT +2. Ahora son las 09:06:12.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi