Visual Basic Foro
Programación => Bases de Datos => Mensaje iniciado por: omarinho23 en Enero 26, 2010, 06:43:33 pm
-
hola que tal de nuevo! haber!! :P bueno todo esta bien... lo unico raro es q la fecha cuando graba se graba con este dia 01/01/1900 ... y no entiendo porque :S
este es mi codigo para guardar
cnn.Execute "INSERT INTO Clientes (voucher, dia, contacto, razonsocial, nºderuc, direccion, inspector, tipodecertificado, cantidad, precio, total, codigodebarra, cit, nºdeplaca, nºdemotor, nºdeserieochasis, nºdecertificado, totalvoucher, boletaofactura, mes, lista, asignacion, observacion) VALUES('" & Text1(1) & "',Convert(DateTime, " & Date & ", 103),'" & Text1(3) & "','" & Text1(4) & "','" & Text1(5) & "','" & Text1(6) & "','" & Text1(7) & "','" & Text1(8) & "','" & Text1(9) & "','" & Text1(10) & "','" & Text1(11) & "','" & Text1(12) & "','" & Text1(13) & "','" & Text1(14) & "','" & Text1(15) & "','" & Text1(16) & "','" & Text1(17) & "','" & Text1(18) & "','" & Text1(19) & "','" & Text1(20) & "','" & Text1(21) & "','" & Text1(22) & "','" & Text1(23) & "')"
-
A ver...
En el Form_Load de tu formulario declara esta variable
Dim FechaActual as Date
Seguido de esto, luego de declararlo, asignale la fecha actual.
FechaActual = Date
Y por último, sustituye el Date de tu Query por FechaActual.
-
no capto.... ???
haber en mi form_load ya agrega dim fechaactual as date
donde pongo
FechaActual = Date
i el resto
-
donde pongo
FechaActual = Date
A ver...
En el Form_Load de tu formulario declara esta variable
Dim FechaActual as Date
Seguido de esto, luego de declararlo, asignale la fecha actual.
FechaActual = Date
Y por último, sustituye el Date de tu Query por FechaActual.
Private Sub Form_Load()
Dim FechaActual as Date
FechaActual = Date
End Sub
Y en el query sustituyes Date por FechaActual y te queda así.
cnn.Execute "INSERT INTO Clientes (voucher, dia, contacto, razonsocial, nºderuc, direccion, inspector, tipodecertificado, cantidad, precio, total, codigodebarra, cit, nºdeplaca, nºdemotor, nºdeserieochasis, nºdecertificado, totalvoucher, boletaofactura, mes, lista, asignacion, observacion) VALUES('" & Text1(1) & "',Convert(DateTime, " & FechaActual & ", 103),'" & Text1(3) & "','" & Text1(4) & "','" & Text1(5) & "','" & Text1(6) & "','" & Text1(7) & "','" & Text1(8) & "','" & Text1(9) & "','" & Text1(10) & "','" & Text1(11) & "','" & Text1(12) & "','" & Text1(13) & "','" & Text1(14) & "','" & Text1(15) & "','" & Text1(16) & "','" & Text1(17) & "','" & Text1(18) & "','" & Text1(19) & "','" & Text1(20) & "','" & Text1(21) & "','" & Text1(22) & "','" & Text1(23) & "')"
-
bueno puse todo pero me señala el error
Incorrect Sysntax near ':'.
y me señala
cnn.Execute "INSERT INTO Clientes (voucher, dia, contacto, razonsocial, nºderuc, direccion, inspector, tipodecertificado, cantidad, precio, total, codigodebarra, cit, nºdeplaca, nºdemotor, nºdeserieochasis, nºdecertificado, totalvoucher, boletaofactura, mes, lista, asignacion, observacion) VALUES('" & Text1(1) & "',Convert(DateTime, " & FechaActual & ", 103),'" & Text1(3) & "','" & Text1(4) & "','" & Text1(5) & "','" & Text1(6) & "','" & Text1(7) & "','" & Text1(8) & "','" & Text1(9) & "','" & Text1(10) & "','" & Text1(11) & "','" & Text1(12) & "','" & Text1(13) & "','" & Text1(14) & "','" & Text1(15) & "','" & Text1(16) & "','" & Text1(17) & "','" & Text1(18) & "','" & Text1(19) & "','" & Text1(20) & "','" & Text1(21) & "','" & Text1(22) & "','" & Text1(23) & "')"
entonces esta bien asi como lo puse
Option Explicit
Enum EACCION
AGREGAR_REGISTRO = 0
EDITAR_REGISTRO = 1
End Enum
Public IdRegistro
Public ACCION As EACCION
Private Sub cmdGuardar_Click()
Dim FechaActual As Date
Text1(11).Text = ((Val(Text1(9).Text) * Val(Text1(10).Text)))
Text1(22).Text = ((Val(Text1(11).Text * 0.3) / 1.19))
'Agrega el registro
'''''''''''''''''''''''''''''''
Select Case ACCION
Case EDITAR_REGISTRO
cnn.Execute "UPDATE Clientes set voucher = '" & Text1(1) & _
"', dia = '" & Text1(2) & _
"', contacto = '" & Text1(3) & _
"', razonsocial = '" & Text1(4) & _
"', nºderuc = '" & Text1(5) & _
"', direccion = '" & Text1(6) & _
"', inspector = '" & Text1(7) & _
"', tipodecertificado = '" & Text1(8) & _
"', cantidad = '" & Text1(9) & _
"', precio = '" & Text1(10) & _
"', total= '" & Text1(11) & _
"', codigodebarra = '" & Text1(12) & _
"', cit = '" & Text1(13) & _
"', nºdeplaca = '" & Text1(14) & _
"', nºdemotor = '" & Text1(15) & _
"', nºdeserieochasis = '" & Text1(16) & _
"', nºdecertificado = '" & Text1(17) & _
"', totalvoucher = '" & Text1(18) & _
"', boletaofactura = '" & Text1(19) & _
"', mes = '" & Text1(20) & _
"', lista = '" & Text1(21) & _
"', asignacion = '" & Text1(22) & _
"', observacion = '" & Text1(23) & _
"' where Cod = " & IdRegistro & ""
Case AGREGAR_REGISTRO
cnn.Execute "INSERT INTO Clientes (voucher, dia, contacto, razonsocial, nºderuc, direccion, inspector, tipodecertificado, cantidad, precio, total, codigodebarra, cit, nºdeplaca, nºdemotor, nºdeserieochasis, nºdecertificado, totalvoucher, boletaofactura, mes, lista, asignacion, observacion) VALUES('" & Text1(1) & "',Convert(DateTime, " & FechaActual & ", 103),'" & Text1(3) & "','" & Text1(4) & "','" & Text1(5) & "','" & Text1(6) & "','" & Text1(7) & "','" & Text1(8) & "','" & Text1(9) & "','" & Text1(10) & "','" & Text1(11) & "','" & Text1(12) & "','" & Text1(13) & "','" & Text1(14) & "','" & Text1(15) & "','" & Text1(16) & "','" & Text1(17) & "','" & Text1(18) & "','" & Text1(19) & "','" & Text1(20) & "','" & Text1(21) & "','" & Text1(22) & "','" & Text1(23) & "')"
End Select
rs.Requery 1
Call CargarListView(FrmPrincipalCarmen.LV, rs)
FechaActual = Date
DoEvents
Unload Me
Set FrmEditCarmen = Nothing
Exit Sub
ErrorSub:
MsgBox Err.Description
End Sub
Private Sub cmdCancelar_Click()
Unload Me
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Unload Me
End If
End Sub
Private Sub Text1_Change(Index As Integer)
Text1(22) = Format(Text1(22), "#0.00")
Text1(11) = Format(Text1(11), "#0.00")
Text1(18) = Format(Text1(18), "#0.00")
End Sub
-
Mira, yo ya no me complico la vida porque ese tema siempre me ha sido muy molesto, yo ahora hago esto:
Dim sqlDate as String
sqlDate = Format (Date, "YYYY/MM/DD")
y en tu código de inserción o actualización (ajustando la cadena claro):
...Text1(1) & ", '" & sqlDate & "', " & Text1(3) & ...
Y si lo que quieres es guardar con el formato largo entonces:
sqlDate = Format (Date, "YYYY/MM/DD HH:MM:SS")
y nunca mas tuve problemas.
-
wow YvanB! ... muchas gracias! me salvaste! ... gracias ssccaann por tu tiempo tomado tmb! muchas gracias muchachos!