Foros del Web » Programación para mayores de 30 ;) » Programación General » Visual Basic clásico »

boton guardar y eliminar

Estas en el tema de boton guardar y eliminar en el foro de Visual Basic clásico en Foros del Web. yo pense que esto me resultaria facil, pero veo que no son enchiladas, ya estube tratando y creo que ando perdido en el espacio. ¿¿¿alguien ...
  #1 (permalink)  
Antiguo 30/03/2006, 13:01
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
boton guardar y eliminar

yo pense que esto me resultaria facil, pero veo que no son enchiladas, ya estube tratando y creo que ando perdido en el espacio.
¿¿¿alguien seria tan amable de decirme como es por favor???

estos son los codigos que he utilizado:

.AddNew !usuario = UCase(Trim(Text1)) & _
!contraseña = UCase(Trim(Text2)) & _
!nombre = UCase(Trim(Text3)) & _
!nivel = UCase(Trim(Text4))

.AddNew !usuario = Text1.text & _
!contraseña = Text2.text & _
!nombre = Text3.text & _
!nivel = Text4.text

de antemano gracias por su ayuda!!!!!
__________________
Vampirito
  #2 (permalink)  
Antiguo 30/03/2006, 13:54
Usuario no validado
 
Fecha de Ingreso: enero-2006
Mensajes: 5
Antigüedad: 18 años, 3 meses
Puntos: 0
[code]
.AddNew
!usuario = UCase(Trim(Text1))
!contraseña = UCase(Trim(Text2))
!nombre = UCase(Trim(Text3))
!nivel = UCase(Trim(Text4))
.Update

.AddNew
!usuario = Text1.text
!contraseña = Text2.text
!nombre = Text3.text
!nivel = Text4.text
.Update
  #3 (permalink)  
Antiguo 30/03/2006, 14:04
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
este es mi codigo:

Dim Sql As String
Dim Rst As New ADODB.Recordset

Sql = "Select * from usuarios where usuario = '" & UCase(Trim(Text1)) & "'"
With Rst
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Source = Sql
Set .ActiveConnection = cnn
.Open
If Not .EOF And Not .BOF Then
MsgBox "ya existe"
Else
.AddNew !usuario = UCase(Trim(Text1)) & _
!contraseña = UCase(Trim(Text2)) & _
!nombre = UCase(Trim(Text3)) & _
!nivel = UCase(Trim(Text4))
.Update
MsgBox "Registro Guardado"
End If
End With
me marca error en la parte donde estan las letras amarillas.
el error es el siguiente:
el valor de bof o eof es true, o el actual registro se elimino; la operacion solicitada requiere un registro actual
__________________
Vampirito
  #4 (permalink)  
Antiguo 30/03/2006, 14:09
Avatar de Frehley  
Fecha de Ingreso: junio-2005
Ubicación: Somewhere between Heaven and Hell
Mensajes: 415
Antigüedad: 18 años, 10 meses
Puntos: 0
El primer registro que guardes siempre te va a tirar error. Poné On Error Resume Next al comienzo del evento y fijate si se guarda todo en la base de datos.
__________________
diegoz.com.ar
  #5 (permalink)  
Antiguo 30/03/2006, 14:14
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
ahora me marca:
error de compilacion
Se esperaba una funcion o variable.
y me marca esta parte del codigo en azul:

.AddNew!usuario = UCase(Trim(Text1)) & _
!contraseña = UCase(Trim(Text2)) & _
!nombre = UCase(Trim(Text3)) & _
!nivel = UCase(Trim(Text4))
.Update
__________________
Vampirito
  #6 (permalink)  
Antiguo 30/03/2006, 14:14
Usuario no validado
 
Fecha de Ingreso: enero-2006
Mensajes: 5
Antigüedad: 18 años, 3 meses
Puntos: 0
Código:
Dim Sql As String
Dim Rst As New ADODB.Recordset

Sql = "Select * from usuarios where usuario = '" & UCase(Trim(Text1)) & "'"
With Rst
    .LockType = adLockOptimistic
    .CursorType = adOpenKeyset
    .Source = Sql
    Set .ActiveConnection = cnn
    .Open
    If Not .EOF And Not .BOF Then
    MsgBox "ya existe"
    Else
       .AddNew
        !usuario = UCase(Trim(Text1))
        !contraseña = UCase(Trim(Text2))
        !nombre = UCase(Trim(Text3))
        !nivel = UCase(Trim(Text4))
        .Update
        MsgBox "Registro Guardado"
    End If
End With
  #7 (permalink)  
Antiguo 30/03/2006, 14:50
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
ok bueno, ya no me marca ningun error, solo hay un pequeño problema:
"NO GUARDA NADA"!!!!!
__________________
Vampirito
  #8 (permalink)  
Antiguo 30/03/2006, 14:54
Avatar de Frehley  
Fecha de Ingreso: junio-2005
Ubicación: Somewhere between Heaven and Hell
Mensajes: 415
Antigüedad: 18 años, 10 meses
Puntos: 0
Sacale el On Error Resume Next y decinos que error te tira. Cuando esté solucionado agregaselo de vuelta.
__________________
diegoz.com.ar
  #9 (permalink)  
Antiguo 30/03/2006, 15:15
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
el error es el siguiente:

error '-2147217873 (80040e2f)' en tiempo de ejecucion:
no se puede insertar el valor null en la columna 'nivel', tabla 'sistema.dbo.usuarios'.la columna no admite valores null.insert falla.
__________________
Vampirito
  #10 (permalink)  
Antiguo 30/03/2006, 15:20
Avatar de vbx3m  
Fecha de Ingreso: febrero-2005
Ubicación: Venezuela
Mensajes: 524
Antigüedad: 19 años, 3 meses
Puntos: 1
Puedes probar con este codigo...
Código:
Dim Rst As ADODB.Recordset
Set Rst= New ADODB.Recordset
Rst.CursorLocation=adUseClient
Rst.Open "Select * from usuarios where usuario = '" & UCase(Trim(Text1)) & "'", cnn, adOpenStatic, adLockOptimistic, adCmdText
If Not Rst.EOF Then
    MsgBox "ya existe"
Else
   Rst.AddNew 
   Rst!usuario = UCase(Trim(Text1)) 
   Rst!contraseña = UCase(Trim(Text2)) 
   Rst!nombre = UCase(Trim(Text3))
   Rst!nivel = UCase(Trim(Text4))
   Rst.Update
   Rst.Close
   Set Rst= Nothing  
   MsgBox "Registro Guardado"
End If
__________________
ホルヘ・ラファエル・マルティネス・レオン

Última edición por vbx3m; 30/03/2006 a las 15:42
  #11 (permalink)  
Antiguo 30/03/2006, 15:29
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
ahora me manda:

referencia no valida o sin calificar
y me marca en azul:

If Not .EOF And Not .BOF Then
__________________
Vampirito
  #12 (permalink)  
Antiguo 30/03/2006, 15:41
Avatar de vbx3m  
Fecha de Ingreso: febrero-2005
Ubicación: Venezuela
Mensajes: 524
Antigüedad: 19 años, 3 meses
Puntos: 1
Claro... solo colocas
Código:
 If Not Rst.EOF Then .....
__________________
ホルヘ・ラファエル・マルティネス・レオン
  #13 (permalink)  
Antiguo 30/03/2006, 15:49
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
yesssssssssssssssssssssssssssssss!!!!!!!!!!!!!!!
por fin!!!!!
ya quedo!!!!!!
ahora solo una pregunta????
la parte de eliminar es casi igual o solo le pongo????
rst.Delete
__________________
Vampirito
  #14 (permalink)  
Antiguo 30/03/2006, 15:54
Avatar de vbx3m  
Fecha de Ingreso: febrero-2005
Ubicación: Venezuela
Mensajes: 524
Antigüedad: 19 años, 3 meses
Puntos: 1
Ummm.. seria algo como

Código:
cnn.Execute "DELETE  FROM Tabla Where campo = '" & condicion & "'"
__________________
ホルヘ・ラファエル・マルティネス・レオン
  #15 (permalink)  
Antiguo 30/03/2006, 15:59
Avatar de vampirito  
Fecha de Ingreso: enero-2004
Ubicación: h.frias 218-301
Mensajes: 121
Antigüedad: 20 años, 4 meses
Puntos: 0
ok, mil gracias!!!!
ya quedo!!!!

pongo el codigo completo para el que lo necesite

Option Explicit

Private cnn As ADODB.Connection
Private Rst As ADODB.Recordset

Private Sub Command1_Click()
Dim Rst As ADODB.Recordset
Set Rst = New ADODB.Recordset
Rst.CursorLocation = adUseClient
Rst.Open "Select * from usuarios where usuario = '" & UCase(Trim(Text1)) & "'", cnn, adOpenStatic, adLockOptimistic, adCmdText
If Not Rst.EOF Then
MsgBox "ya existe"
Else
Rst.AddNew
Rst!usuario = UCase(Trim(Text1))
Rst!contraseña = UCase(Trim(Text2))
Rst!nombre = UCase(Trim(Text3))
Rst!nivel = UCase(Trim(Text4))
Rst.Update
Rst.Close
Set Rst = Nothing
MsgBox "Registro Guardado"
End If
End Sub

Private Sub Command2_Click()
cnn.Execute "DELETE FROM usuarios Where usuario = '" & UCase(Trim(Text1)) & "'"
End Sub

Private Sub Form_Load()
Set cnn = Nothing
Set Rst = Nothing
Set cnn = New ADODB.Connection
Set Rst = New ADODB.Recordset

cnn.ConnectionString = "Provider= SQLOLEDB.1;" & _
"Persist Security Info= False;" & _
"Integrated Security= SSPI;" & _
"Password= sa; User ID= sa; " & _
"Initial Catalog=sistema; " & _
"Data Source= (local);"
cnn.Open

End Sub
__________________
Vampirito
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:21.