• Jueves 18 de Abril de 2024, 15:08

Autor Tema:  Problema con Fecha  (Leído 2178 veces)

korsakof

  • Miembro activo
  • **
  • Mensajes: 36
  • Nacionalidad: es
    • Ver Perfil
Problema con Fecha
« en: Lunes 4 de Abril de 2011, 20:11 »
0
Código: vb.net
  1.     Dim resp As Boolean
  2.  
  3.         resp = comprobarCampos()
  4.         If resp = True Then
  5.  
  6.             REM meto consulta numalum
  7.  
  8.             Dim oDataadapter As New SqlDataAdapter
  9.             '  Dim oComando As New SqlCommand(sSQL, CONN)
  10.             Dim iResultado As Integer
  11.  
  12.             Dim oComando As New SqlCommand("INSERT INTO Frutas (idCursoFruta,idAlumnoFruta,fecha,nFrutas) VALUES(@idCursoFruta,@idAlumnoFruta,@fecha,@nFrutas)", CONN)
  13.             oDataadapter.InsertCommand = oComando
  14.  
  15.             oDataadapter.InsertCommand.Parameters.Add(New SqlParameter("@idCursoFruta", SqlDbType.Int))
  16.             oDataadapter.InsertCommand.Parameters.Add(New SqlParameter("@idAlumnoFruta", SqlDbType.Int))
  17.             oDataadapter.InsertCommand.Parameters.Add(New SqlParameter("@fecha", SqlDbType.DateTime))
  18.             oDataadapter.InsertCommand.Parameters.Add(New SqlParameter("@nFrutas", SqlDbType.Bit))
  19.  
  20.  
  21.             oDataadapter.InsertCommand.Parameters("@idCursoFruta").Value = LTrim(RTrim(Val(Microsoft.VisualBasic.Left(cbbCurso.Text, 2))))
  22.             oDataadapter.InsertCommand.Parameters("@idAlumnoFruta").Value = LTrim(RTrim(Val(Microsoft.VisualBasic.Left(cbbNumAlum.Text, 2))))
  23.  
  24.  
  25.             Esta es la linea------->oDataadapter.InsertCommand.Parameters("@fecha").Value = CDate(Format$(dtpFecha.Value.Date, "yyyy-MM-dd"))
  26.  
  27.  
  28.             oDataadapter.InsertCommand.Parameters("@nFrutas").Value = chkFruta.CheckState
  29.  
  30.             CONN.Open()
  31.             ' ejecutar comando de inserción del adaptador
  32.             iResultado = oDataadapter.InsertCommand.ExecuteNonQuery()
  33.             ' cerrar conexión
  34.             CONN.Close()
  35.  
  36.  
  37.             MsgBox("Se añadio el registro con exito", MsgBoxStyle.OkOnly)
  38.             botones(2)
  39.             carganumAlum()
  40.  
  41.         Else
  42.             MsgBox("Algun dato introducido es incorrecto", MsgBoxStyle.OkOnly)
  43.         End If
  44.  

Tengo un problema al introducir la fecha, ya que no me añade solo la fecha sino tambien la hora. en la base de datos el campo esta declarado como datetime.


Gracias.  :hitcomp:

gabio2

  • Miembro MUY activo
  • ***
  • Mensajes: 402
  • Nacionalidad: mx
    • Ver Perfil
Re: Problema con Fecha
« Respuesta #1 en: Martes 5 de Abril de 2011, 17:02 »
0
Código: vb.net
  1.  
  2.      Esta es la linea------->oDataadapter.InsertCommand.Parameters("@fecha").Value = CDate(Format$(dtpFecha.Value.Date, "yyyy-MM-dd")).ToShortDateString() ' Esto solo te da la fecha sin hora
  3.  
  4.  

:D
@gabio87

korsakof

  • Miembro activo
  • **
  • Mensajes: 36
  • Nacionalidad: es
    • Ver Perfil
Re: Problema con Fecha
« Respuesta #2 en: Jueves 7 de Abril de 2011, 15:11 »
0
Cita de: "gabio2"
Código: vb.net
  1.  
  2.      Esta es la linea------->oDataadapter.InsertCommand.Parameters("@fecha").Value = CDate(Format$(dtpFecha.Value.Date, "yyyy-MM-dd")).ToShortDateString() ' Esto solo te da la fecha sin hora
  3.  
  4.  

:D


No funciona!!!, Gracias por la respuesta.