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
giantonti1801 giantonti1801 is offline
Miembro
 
Registrado: oct 2022
Posts: 143
Poder: 2
giantonti1801 Va por buen camino
Cita:
Empezado por cloayza Ver Mensaje
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
Perfecto pero estos valores estan contenidos en ul label2.capcion, ahora no se como colocarlo alli
Responder Con Cita
  #2  
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
Cita:
Empezado por giantonti1801 Ver Mensaje
Perfecto pero estos valores estan contenidos en ul label2.capcion, ahora no se como colocarlo alli
Código Delphi [-]
ADOQueryUpdate.Parameters.ParamByName('Estatus').Value := labelelquesea.caption;
ADOQueryUpdate.Parameters.ParamByName('Nombre').Value  := labelotra.caption;
ADOQueryUpdate.Parameters.ParamByName('Apellido').Value:= labelyoquese.caption;

No estaría de más que le echaras un vistazo a este libro, te abrirá los ojos.
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 Casimiro Notevi Ver Mensaje
Código Delphi [-]
ADOQueryUpdate.Parameters.ParamByName('Estatus').Value := labelelquesea.caption;
ADOQueryUpdate.Parameters.ParamByName('Nombre').Value  := labelotra.caption;
ADOQueryUpdate.Parameters.ParamByName('Apellido').Value:= labelyoquese.caption;

No estaría de más que le echaras un vistazo a este libro, te abrirá los ojos.

Ahora me esta dando otro error no logro identificarlo

Código Delphi [-]
Close;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket');
        ADOQueryUpdate.SQL.Add( 'SET');
        ADOQueryUpdate.SQL.Add( 'Estatus =:Estatus,');
        ADOQueryUpdate.SQL.Add( 'Usuario  =:Usuario,');
        ADOQueryUpdate.SQL.Add(' WHERE Item =:Item');
        //Asignación de valores a los parametros...
        //Precaución con los tipos de datos
        ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.Parameters.ParamByName('Estatus').Value :='OLD';
        ADOQueryUpdate.Parameters.ParamByName('Usuario').Value := Label4.caption;

        ADOQueryUpdate.ExecSQL;

NOTA: Error ' Incorrect Syntax near the 'WHERE'

Última edición por giantonti1801 fecha: 29-03-2023 a las 20:43:36.
Responder Con Cita
  #4  
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
Según el siguiente ejemplo que usted indicó...
Código SQL [-]
Update Tiket set Estatus = 'NEW' Where Item = '2'

Item= Es de tipo STRING

Y lo estas convirtiendo a entero...

Código Delphi [-]
ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);

Lo que se traduce en una instrucción como la que sigue...
Código SQL [-]
Update Tiket set Estatus = 'NEW' Where Item = 2

Ese debe ser el origen del error

Verifique los tipos de datos...como mencione antes...

Saludos cordiales
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 cloayza Ver Mensaje
Según el siguiente ejemplo que usted indicó...
Código SQL [-]
Update Tiket set Estatus = 'NEW' Where Item = '2'

Item= Es de tipo STRING

Y lo estas convirtiendo a entero...

Código Delphi [-]
ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);

Lo que se traduce en una instrucción como la que sigue...
Código SQL [-]
Update Tiket set Estatus = 'NEW' Where Item = 2

Ese debe ser el origen del error

Verifique los tipos de datos...como mencione antes...

Saludos cordiales
Código Delphi [-]
ADOQuery1Item: TAutoIncField;

Es autonumerico pero lo que debo hacer es solo leerlo pero entonces el problema puede ser que venga de aqui ya que es este punto yo le estoy pasando el valor ITEM para luego leerlo
Código Delphi [-]
Label3.Caption := ADOQuery1.fieldbyname('MINIMO').asstring;
[/delphi]
ADOQueryUpdate.SQL.Add( 'WHERE Item =:Item,');
ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);
[/delphi]
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
Código Delphi [-]
ADOQuery1Item: TAutoIncField;

Es autonumerico pero lo que debo hacer es solo leerlo pero entonces el problema puede ser que venga de aqui ya que es este punto yo le estoy pasando el valor ITEM para luego leerlo
Código Delphi [-]
Label3.Caption := ADOQuery1.fieldbyname('MINIMO').asstring;
[/delphi]
ADOQueryUpdate.SQL.Add( 'WHERE Item =:Item,');
ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);
[/delphi]
Ya vi donde esta el problema pero si voy a necesitar ayuda

Código Delphi [-]
procedure TFormCaja.SpeedButton1Click(Sender: TObject);
begin
    With ADOQuery1 do
        begin
        Close;
        Open;
        ADOQuery1.First;
         begin
         Label1.Caption := 'A00' + ADOQuery1.fieldbyname('MINIMO').asstring;
         Label3.Caption := ADOQuery1.fieldbyname('MINIMO').asstring;
         Image3.Visible := true;
         begin
         With ADOQueryUpdate do
         Close;
         Open;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket');
        ADOQueryUpdate.SQL.Add( 'SET');
        ADOQueryUpdate.SQL.Add( 'Estatus =:Estatus,');
        ADOQueryUpdate.SQL.Add( 'Usuario  =:Usuario,');
        ADOQueryUpdate.SQL.Add( 'WHERE Item =:Item,');
        //Asignación de valores a los parametros...
        //Precaución con los tipos de datos
        ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.Parameters.ParamByName('Estatus').Value :='OLD';
        ADOQueryUpdate.Parameters.ParamByName('Usuario').Value := Label4.caption;
        ADOQueryUpdate.ExecSQL;
        //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;


      end;
end;


Resulta que me esta dando error porque como es el primer procedimiento aun el Label3.caption esta vacio por ellos me da este error debo colocar un IF pero no se donde poderlo colocar para que me funciones, es decir si el laber3.caption esta vacio que solamente corra la primera instrucion

Código Delphi [-]
procedure TFormCaja.SpeedButton1Click(Sender: TObject);
begin
    With ADOQuery1 do
        begin
        Close;
        Open;
        ADOQuery1.First;
         begin
         Label1.Caption := 'A00' + ADOQuery1.fieldbyname('MINIMO').asstring;
         Label3.Caption := ADOQuery1.fieldbyname('MINIMO').asstring;
         Image3.Visible := true;
         begin


de lo contrario que la recorra toda:

Código Delphi [-]
procedure TFormCaja.SpeedButton1Click(Sender: TObject);
begin
    With ADOQuery1 do
        begin
        Close;
        Open;
        ADOQuery1.First;
         begin
         Label1.Caption := 'A00' + ADOQuery1.fieldbyname('MINIMO').asstring;
         Label3.Caption := ADOQuery1.fieldbyname('MINIMO').asstring;
         Image3.Visible := true;
         begin
         With ADOQueryUpdate do
         Close;
         Open;
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket');
        ADOQueryUpdate.SQL.Add( 'SET');
        ADOQueryUpdate.SQL.Add( 'Estatus =:Estatus,');
        ADOQueryUpdate.SQL.Add( 'Usuario  =:Usuario,');
        ADOQueryUpdate.SQL.Add( 'WHERE Item =:Item,');
        //Asignación de valores a los parametros...
        //Precaución con los tipos de datos
        ADOQueryUpdate.Parameters.ParamByName('Item').Value := StrToInt(Label3.Caption);
        ADOQueryUpdate.Parameters.ParamByName('Estatus').Value :='OLD';
        ADOQueryUpdate.Parameters.ParamByName('Usuario').Value := Label4.caption;
        ADOQueryUpdate.ExecSQL;
        //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;

Última edición por dec fecha: 04-11-2022 a las 07:40:21. Razón: Edición etiquetas DELPHI
Responder Con Cita
  #7  
Antiguo 04-11-2022
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.735
Poder: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Aquí te sobran comas:

Código Delphi [-]
        ADOQueryUpdate.SQL.Add( 'UPDATE Tiket');
        ADOQueryUpdate.SQL.Add( 'SET');
        ADOQueryUpdate.SQL.Add( 'Estatus =:Estatus,');
        ADOQueryUpdate.SQL.Add( 'Usuario  =:Usuario,');
        ADOQueryUpdate.SQL.Add( 'WHERE Item =:Item,');

Código SQL [-]
UPDATE Tiket
SET
Estatus =:Estatus,
Usuario  =:Usuario,  //<-- esta coma está de mas. Implica que hay otro campo para actualizar
WHERE Item =:Item,   //<-- esta coma está de mas. Esta condición es lógica, del tipo "(item=:item) and (estatus='OLD')"
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 21:42:31.


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