Siempre graba 01/01/1900

15/09/2004 - 21:52 por Carmelo Gonzalez | Informe spam
Hola !!!
Disculpen la molestia
ya pude hacer el UPDATE pero ahora falta el Insert

MiComando.CommandText = "INSERT INTO MovimientoCaja (Codigo, NroMovimiento,
Fecha, NroOrigen) Values ('" & cCodCaj & "', '" & sCad & "', " &
CType(txtFecha.Text, DateTime) & ", '" & txtDocumento.Text & "')"

"INSERT INTO MovimientoCaja (Codigo, NroMovimiento, Fecha, NroOrigen) Values
('0003', '0000000079', 15/09/2004, '222')"

Graba pero la fecha siempre es 01/01/1900, el UPDATE lo solucione asi:
Dim sFecha As String

sFecha = txtFecha.Value.Month & "/" & txtFecha.Value.Day & "/" &
txtFecha.Value.Year

MiComando.CommandText = "UPDATE MovimientoCaja SET NroOrigen = '" &
txtDocumento.Text & "', Origen = '" & txtOrigen.Text & "', Fecha ='" &
sFecha & "' WHERE NroMovimiento = '" & XXX & "'"

Gracias por toda la Ayuda
 

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP VB]
16/09/2004 - 01:25 | Informe spam
MiComando.CommandText = "INSERT INTO MovimientoCaja (Codigo,
NroMovimiento, Fecha, NroOrigen) Values ('" & cCodCaj & "', '" & sCad
& "', " & CType(txtFecha.Text, DateTime) & ", '" & txtDocumento.Text
& "')"



Concatenar los datos en el SQL nunca fue buena idea ya que ademas de los
problemas de seguridad que trae tienes los problemas con el formato de los
datos. Utiliza parametros para pasar los datos al comando:

MiComando.CommandText = "INSERT INTO MovimientoCaja (Codigo, NroMovimiento,
Fecha, NroOrigen) " & _
"Values (@codigo, @nromovimiento, @fecha,
@nroorigen)"
MiComando.Parameters.Add("@codigo", cCodCaj)
MiComando.Parameters.Add("@nromovimiento", sCad)
MiComando.Parameters.Add("@fecha", CType(txtFecha.Text, DateTime))
MiComando.Parameters.Add("@nroorigen", txtDocumento.Text)
MiComando.ExecuteNonQuery()

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo

Preguntas similares