Ayuda con un login en sql server y visual basic
Publicado por Emanuel (3 intervenciones) el 04/12/2019 06:15:53
cuando compilo no me sale ningun error pero cuando me lanza al inicio de sesion y pongo los datos y le doy a entrar me aparece este error..
Aqui les paso el codigo del programa
-conexion.vb
-Form1.vb


Aqui les paso el codigo del programa
-conexion.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Imports System.Data.Sql
Imports System.Data.SqlClient
Module ConexionBD
Public conexion As SqlConnection
Public enunciado As SqlCommand
Public respuesta As SqlDataReader
Sub abrir()
Try
conexion = New SqlConnection("Data Source=DESKTOP-E3NHR8P\SQLEXPRESS;Initial Catalog=iSongBD;Integrated Security=True")
conexion.Open()
MsgBox("conectado")
Catch ex As Exception
MsgBox("no se puede conectar" + ex.ToString)
End Try
End Sub
Function usuarioRegistrado(ByVal nombreUsuario As String) As Boolean
Dim resultado As Boolean = False
Try
enunciado = New SqlCommand("Select * from Usuarios where Usuario='" & nombreUsuario & "'", conexion)
respuesta = enunciado.ExecuteReader
If respuesta.Read Then
resultado = True
End If
respuesta.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return resultado
End Function
Function contraseña(ByVal nombreUsuario As String) As String
Dim resultado As String = ""
Try
enunciado = New SqlCommand("Select Contraseña from Usuarios where Usuario='" & nombreUsuario & "'", conexion)
respuesta = enunciado.ExecuteReader
If respuesta.Read Then
resultado = respuesta.Item("Contraseña")
End If
respuesta.Close()
Return resultado
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
End Module
-Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Public Class Form1
Private txtUsuario As Object
Private txtContraseña As Object
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
abrir()
End Sub
Private Sub Button_1Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
If usuarioRegistrado(txtUsuario.Text) = True Then
Dim contra As String = contraseña(txtUsuario.Text)
If contra.Equals(txtContraseña.Text) = True Then
FrmPrincipal.ShowDialog()
Else
MsgBox("Contraseña Invalida", MsgBoxStyle.Critical)
End If
Else
MsgBox("El Usuario: " + txtUsuario.Text + " no se encuentra registrado")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class


Valora esta pregunta


0