Nuevas NORMAS para el foro

Curso Hacker
Bienvenido(a), Visitante. Favor de ingresar o registrarse.
¿Perdiste tu email de activación? - Agosto 07, 2008, 06:40:40
Boton Buscar
Inicio Ayuda Ingresar Registrarse
Visita: Articulos - Juegos Gratis - Da Foros

Comunidad Underground Hispana  |  Programacion  |  Programación  |  Visual Basic y Net (Moderador: ANYD00M)  |  Tema: solucion a out-of-range datetime value 0 Usuarios y 1 Visitante están viendo este tema. « anterior próximo »
Páginas: [1] Ir Abajo Imprimir
Autor Tema: solucion a out-of-range datetime value  (Leído 114 veces)
J@Ker Lo10
Habitual
*****
Desconectado Desconectado

Mensajes: 200


'LA PRimeR @ VivE' J @Ker LOlo

???? ???? ????
Ver Perfil
« en: Julio 06, 2007, 11:13:17 »

hola..
Posteo la solucion para este error en Visual Basic 6.0-> out-of-range datetime value.

contexto:

Se cuenta con una tabla en SQL 2000 con un campo Datetime,
el probelma surge al querer hacer cambios o actualizaciones a la tabla
desde visual basic.

//Datetiem almacena tanto la feha como la hora

Create Table TABLA(
      fecha   Datetime not null,
 );


//Desde Visual Basic
Supongamos que creamos un objeto Command y nececitamos hacer un insert

como este.
 Insert into TABLA values(date) //Lo probable dependiendo de la ubicacion
 es que Vb mande el error comentado anteriormente

Esto se soluciona adoptando el estandar ISO para fechas en los manejadores

por lo cual se creala sig. Funcion


Public Function getFechaSQL(ByVal dtFecha As Date) As String
'El formato de fecha standar de ISO es yymmdd
Dim intAño As Integer
Dim intMes As Integer
Dim intDia As Integer
Dim strFecha As String
intDia = Day(dtFecha)
intMes = Month(dtFecha)
intAño = Year(dtFecha)
strFecha = ""
strFecha = strFecha & intAño
If intMes < 10 Then
   strFecha = strFecha & "0" & intMes
   Else
       strFecha = strFecha & intMes
End If
If intDia < 10 Then
   strFecha = strFecha & "0" & intDia
   Else
       strFecha = strFecha & intDia
End If
getFechaSQL = strFecha
End Function


El insert final quedaria Asi:

 Insert into TABLA values(getFechaSQL(date)) // y wala ya no marcara error

Saludos..

DoloresMtz @gmail.com



En línea

El ConoCIMIenTo no lleGA poR si solo,
soLO kE el MEdio pARA oBteNERlo es ..........
J@Ker Lo10
Habitual
*****
Desconectado Desconectado

Mensajes: 200


'LA PRimeR @ VivE' J @Ker LOlo

???? ???? ????
Ver Perfil
« Respuesta #1 en: Julio 07, 2007, 01:26:21 »

 
Sorry..
Se me paso.. LEvva apostrofes al inserar la fecha

Insert into TABLA values("'" & getFechaSQL(date) & "'") // y wala ya no marcara error
En línea

El ConoCIMIenTo no lleGA poR si solo,
soLO kE el MEdio pARA oBteNERlo es ..........
Páginas: [1] Ir Arriba Imprimir 
Comunidad Underground Hispana  |  Programacion  |  Programación  |  Visual Basic y Net (Moderador: ANYD00M)  |  Tema: solucion a out-of-range datetime value « anterior próximo »
Ir a:  


Ranking-Hits
Powered by SMF 1.1.5 | SMF © 2006-2007, Simple Machines LLC