Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/05/2011, 22:05
Avatar de lokoman
lokoman
 
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 7 meses
Puntos: 47
Respuesta: Comprobar user en base de datos

???

Crear la conexion? (HAZ TODOS ESTOS PASOS PARA ASEGURARTE DE QUE LA CONEXION ESTA CORRECTA)
1. Conexion:
• Añade el componente "Microsoft ADO Data Control 6.0 (OLEDB)"
• Añade el componente al formulario "LOGIN"
• Clic derecho al componente en el formulario
• Seleccionar "ADODC Properties"
• Seleccionar la opcion "Use connection string"
• Clic en "Build", te saldrá un asistente de conexion
• Selecciona el proveedor "Microsoft OLE DB Provider for SQL Server"
• Clic en Siguiente o Next
• Escribir el nombre del Server, User name y Password en los campos corrrespondientes
• Seleccionar la base de datos de la lista "Select the database on the Server"
• Clic en "Test conecction", tiene que salir un cuadro de dialogo que diga "Test connection Succeeded!!"
• Se cerrará el asistente y te dejará en "ADODC Properties", con los datos de conexion, lo seleccionas todo, le das copy

2. Pegas el siguiente CODE en tu formulario "LOGIN", reemplazando el "ConnectionString" por el tuyo:

Código vb:
Ver original
  1. Public ConexionDB As ADODB.Connection
  2.  
  3. Public Sub Conexion()
  4.     Set ConexionDB = New ADODB.Connection
  5.  
  6. 'REEMPLAZA LA CONEXION POR EL TUYO, EL QUE LE DISTE COPY DEL PASO ANTERIOR    
  7.    ConexionDB.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _
  8.         & "User ID=sa;Initial Catalog=Northwind;Data Source=SQLSERVERNAME"
  9.     ConexionDB.Open
  10.    
  11.     If ConexionDB.State = 1 Then
  12.         MsgBox "Se ha establecido la conexion con la BD!!", vbInformation
  13.     Else
  14.         MsgBox "Verificar la conexion a la BD!!", vbExclamation
  15.     End If
  16. End Sub

3. Ya puedes borrar el componente "ADODC" del formulario

4. Consultar datos:
• Añade 2 Textbox: 1) txtUsuarios, 2) txtPassword
• Añade 1 CommandButton: cmdAcceder

Código vb:
Ver original
  1. Private Sub cmdAcceder_Click()
  2.     Dim rstConsultaUser As ADODB.Recordset
  3.     Set rstConsultaUser = New ADODB.Recordset
  4.  
  5.     If Trim(txtUsuario.Text) <> Empty And Trim(txtPassword.Text) <> Empty Then
  6.  
  7. 'CONSULTAR EL USUARIO Y EL PASSWORD EN LA BASE DE DATOS
  8.        rstConsultaUser.Source = "SELECT * FROM TABLA WHERE ID_USUARIO=" _
  9.                                & Trim(txtUsuario.Text) & " AND PASSWORD=" & Trim(txtPassword.Text)
  10.         rstConsultaUser.Open , ConexionDB, adOpenStatic, adLockReadOnly
  11.        
  12.         If rstConsultaUser.EOF = False Then
  13. 'SI LOS DATOS ESTAN CORRECTOS, MOSTRAR EL FORMULARIO PRINCIPAL
  14.            frmMain.Show
  15.         Else
  16.             MsgBox "Datos incorrectos!!" & vbNewLine & "No puede acceder!!", vbInformation
  17.         End If    'Fin del If rstConsultaUser.EOF = False Then
  18.    Else
  19.         MsgBox "Verificar los campos!!", vbInformation
  20.     End If    'Fin del If Trim(txtUsuario.Text) <> Empty And Trim(txtPassword.Text) <> Empty Then
  21.  
  22. 'LIMPIAR LAS REFERENCIAS
  23.    If rstConsultaUser.State = 1 Then rstConsultaUser.Close
  24.     Set rstConsultaUser = Nothing
  25. End Sub

5. Ajusta los datos a los tuyos y nos cuentas!