Visual Basic - problema con base de datos

Life is soft - evento anual de software empresarial
 
Vista:

problema con base de datos

Publicado por william edgar (27 intervenciones) el 27/02/2008 18:04:48
hola amigos, tengo un programa de inventarios, pero tengo el problema que cuando comparo lo que tengo en la base de datos, no me lo reconoce, me refiero al nombre y contraseña, son usuarios por niveles y dependiendo el nivel, es el permiso, les paso el codigo.

Private Sub Command1_Click()
Dim B As Object

On Error GoTo CONTROLERRORES
Data1.Refresh

USUARIOENCONTRADO = 0

'RUTINA DE VALIDAR CAMPOS CON CAMPOS VACIOS
If Text1.Text = "" Or Text2.Text = "" Then
If Text1.Text = "" Then
mensaje = MsgBox("INTRODUZCA EL NOMBRE DEL USUARIO", vbExclamation, "POZ")
Text1.SetFocus
Exit Sub
Else
If Text2.Text = "" Then
mensaje = MsgBox("INTRODUZCA LA CONTRASEÑA DEL USUARIO", vbExclamation, "POZ")
Text2.SetFocus
Exit Sub
End If
End If
End If
'FIN DE RUTINA DE ALTA CON CAMPOS VACIOS

Data1.Recordset.MoveFirst
Data1.Recordset.MoveNext
Do
If Data1.Recordset!NOMBRE = Text1.Text And Data1.Recordset!CLAVEUSUARIO = Text2.Text Then
TIPOUSUARIO = Data1.Recordset!TIPOUSUARIO
If TIPOUSUARIO = "USUARIO NIVEL 1" Then
IBMenuNivel1.StatusBar1.Panels(3).Text = "USUARIO: " & Text1.Text
IBMenuNivel1.Show
Data1.Recordset.MoveLast
USUARIOENCONTRADO = 1
GoTo SALIDA
'Unload Me
Else
IBMenuPrincipal.StatusBar1.Panels(3).Text = "USUARIO: " & Text1.Text
IBMenuPrincipal.Show
'IBMENUPRINCIPAL
USUARIOENCONTRADO = 1
GoTo SALIDA
'Unload Me
End If
' USUARIOENCONTRADO = 0
End If
Data1.Recordset.MoveNext
Loop Until Data1.Recordset.EOF

If USUARIOENCONTRADO = 0 Then
mensaje = MsgBox("USUARIO NO VALIDO, VERIFIQUE SU NOMBRE DE USUARIO Y SU CONTRASEÑA", vbQuestion, "POZ")
Text1.SetFocus
Exit Sub
End If

CONTROLERRORES:
Select Case Err.Number
Case 91
INS = 0
mensaje = MsgBox("LA INSTALACION CONTINUA.......,", vbInformation, "INSTALACION")
IBInstalarPrimeravez.Command1.Enabled = False
INS = 1
'Unload Me
IBInstalarPrimeravez.Show vbModal, Me
If INS = 1 Then
Exit Sub
End If
Case 3044
INS = 0
mensaje = MsgBox("LA INSTALACION CONTINUA.......,", vbInformation, "INSTALACION")
IBInstalarPrimeravez.Command1.Enabled = False
INS = 1
'Unload Me
IBInstalarPrimeravez.Show vbModal, Me
If INS = 1 Then
Exit Sub
End If
Case 3024
INS = 0
mensaje = MsgBox("LA INSTALACION CONTINUA.......,", vbInformation, "INSTALACION")
IBInstalarPrimeravez.Command1.Enabled = False
INS = 1
'Unload Me
IBInstalarPrimeravez.Show vbModal, Me
If INS = 1 Then
Exit Sub
End If
'FIN DE RUTINA
End Select

SALIDA:
Unload Me

End Sub

este codigo es del boton entrar, aqui se comprueba si la contraseña y nombre de usuario son validas.

en la base de datos hay 3 campos.

nombre
tipodeusuario
clavedeusuario

aqui se hace la comparacion para saber el tipo de usuario y asi mismo darle los privilegios a cada uno, pero al darle entrar, le pongo el nombre de usuario y contraseña correctos que tengo en la base de datos, que en este caso seria el usuario nivel 1, y me marca error de nombre de usuario y contraseña, o sea se cumple la condicion que puse al ultimo y no se que este pasando, les agradeceria su ayuda.

gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:problema con base de datos

Publicado por Edwin (303 intervenciones) el 28/02/2008 03:01:11
Ok, para mí sería mejor que lo realizaras con un simple Select ya sea con un objeto Connection o Command.

set record = com.execute (Select count(*) from usuario where usuario = text1 and password = text2)

if record(0) >0 then

set record = com.execute (Select * from usuario where usuario = text1 and password = text2)

Segun tu tabla

Usuario | Password | Tipo
record(0) record(1) record(2)

Solo condicionarias con record(2) el tipo de usuario

if record(2) = "Tipo X" then
bla
bla
bla
elseif....... then
end if
else
msgbox "Datos incorrectos"
end if

Valida mejor los texbox con la función TRIM y si puedes mejora los tipo de usuarios agregandole otar tabla tipousuario, ya que tu código está limitando al parecer dos usuarios.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:problema con base de datos

Publicado por fede (189 intervenciones) el 28/02/2008 15:08:22
aca no deberias poner asi
If Data1.Recordset!NOMBRE = Text1.Text And Data1.Recordset!CLAVEUSUARIO = ' " & Text2.Text Then & " ' o hacerle un trim a text2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar