Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Excepción: is not a valid date (https://www.clubdelphi.com/foros/showthread.php?t=93010)

javicho_villa 19-04-2018 20:21:54

Excepción: is not a valid date
 
Buenas tardes,

Quiero agradecer primero por la atención prestada y pedirles me ayuden con este problemita que ya me esta carcomiendo el cerebro hace varios días.

Estoy programando en XE8 con SQL uso componentes ADO y para insertar una tabla llamada Cliente utilizo un AdoStoreProcedure y tengo un campo de tipo fecha llamado FRegistro donde guardo la fecha en que se creo el registro pero me sale el error: Excepción: is not a valid date, ya he probado de todo usando variables de tipo TDate, TDateTime, funciones que devuelven la fecha del sistemas como Date y Now, pero siempre me sale un error que no reconoce el tipo de fecha.

Aquí les copio lo mas resultante del código utilizado:

Código Delphi [-]
        MyClass := TComponent.Create(Self);
         try
           try
             with Datos.DatosDM.PrincipalADOStoredProc do
               begin
                 Close;
                 Parameters.Clear;
                 if ledita=false then
                   begin
                     Parameters.ParseSQL('ClienteInsertar',TRUE);
                     ProcedureName := 'ClienteInsertar';
                   end
....
....
                Parameters.CreateParameter('@TituloDoc3',ftString,pdInput,30,0);          //24
                 if ledita=false then
                   begin
                     Parameters.CreateParameter('@Id_Usuario',ftInteger,pdInput,30,0);         //25
                     Parameters.CreateParameter('@FRegistro',ftDate,pdInput,0,0);              //26
                   end;
.....
....

                 if ledita=false then
                   begin
                     Parameters.ParamByName('@Id_Usuario').Value        := 0;         //25
                     Parameters.ParamByName('@FRegistro').Value         := StrToDate(formatdatetime('YYYY-MM-DD',Date));  
                   end;

                 Parameters.ParamByName('@TituloDetallePedido').Value   := self.TituloDetallePedidoEdit.Text;   //27
                 Parameters.ParamByName('@MiMensaje').Value             := '';//28 PARAMETRO DE SALIDA
                 lacepta := true;
               end;
             Datos.DatosDM.PrincipalADOStoredProc.Prepared := true;
             Datos.DatosDM.PrincipalADOStoredProc.ExecProc;

          finally
             if not VarIsNull(Datos.DatosDM.PrincipalADOStoredProc.Parameters.ParamByName('@MiMensaje').Value) then
                 MiMsjBD := Datos.DatosDM.PrincipalADOStoredProc.Parameters.ParamByName('@MiMensaje').Value;
             MyClass.Free;
           end;
           Except
             ON Error: Exception DO ShowMessage ('Excepción: '+Error.Message);
         end;
       end;


De antemano muchas gracias por leer este post.

Casimiro Notevi 19-04-2018 21:57:21

Mira exactamente qué tipo de dato tiene definido el campo en la tabla.
Mira exactamente el parámetro que se está pasando al procedimiento.

javicho_villa 19-04-2018 22:19:04

Datos de la tabla
 
Gracias por la respuesta, paso los datos:

Uso SQL
Tabla : Cliente
Campo: FRegistro
Tipo: Date (No existe tipo DateTime como en el delphi, por ahi quizas este el error)

Delphi:
lo creo así:
Código Delphi [-]
Parameters.CreateParameter('@FRegistro',ftDate,pdInput,0,0);
Parameters.ParamByName('@FRegistro').Value   := StrToDate(formatdatetime('YYYY-MM-DD',Date));

He probado cambiando el formato de la fecha DD-MM-YYYY; YYYY/MM/DD; todas las combinaciones existentes, pero igual no acepta el valor
Tambien probe con una variable de tipo TDate y tambien de tipo TDateTime, y me da el mismo error

javicho_villa 19-04-2018 23:25:39

Solución - Orden De Campos En El Procedimiento
 
Ante todo gracias por leer el post.

La solución estaba en corregir el procedimiento almacenado en el orden del insert, el campo FRegistro recibia un parametro de tipo varchar solo por el orden en el cual esta el código, finalmente puse de frente el valor Date del sistema en el parametro y funcionó.

Una tontería pero que te quita tiempo, espero tener mas cuidado para la próxima, muchas gracias a todos.


La franja horaria es GMT +2. Ahora son las 17:58:47.

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