使用datareader VB.NET和SQL Server显示数据时出错

使用datareader VB.NET和SQL Server显示数据时出错,vb.net,Vb.net,我试图在登录成功后显示用户角色,但是,我无法获得我想要的行为。我是一个初学者,在这里我把我的代码放在我现在使用的地方 Sub LoginSistema() Try AbrirConexion() Comando = New SqlCommand("select * from tbl_usuarioslogin where username = '" & frmLoginWindow.TextBox1.Text & "' and passw

我试图在登录成功后显示用户角色,但是,我无法获得我想要的行为。我是一个初学者,在这里我把我的代码放在我现在使用的地方

 Sub LoginSistema()
    Try
        AbrirConexion()
        Comando = New SqlCommand("select * from tbl_usuarioslogin where username = '" & frmLoginWindow.TextBox1.Text & "' and password = '" & frmLoginWindow.TextBox2.Text & "'")
        Comando.CommandType = CommandType.Text
        Comando.Connection = Conexion
        Lector = Comando.ExecuteReader()
        If Lector.HasRows Then
            Lector.Read()
            If Lector.GetValue(1).ToString = "Victor" Then
                MsgBox("Bienvenido :) " + Lector(8).ToString())
                CerrarConexion()
                Lector.Close()
            Else
                MsgBox("Error al iniciar sesion en el Sistema.")
                CerrarConexion()
                Lector.Close()
            End If
        Else
            MsgBox("No hay datos leidos de la base de datos.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

请参见,请提供发生错误的详细信息,包括错误发生的位置,或者准确描述实际行为与您预期的不同。你所做的只是说“这是我的代码,它不工作”。我们需要你具体一点。而且,你查询数据库的方式非常糟糕。错误的数据可能会生成异常,从而阻止合法用户登录,恶意用户可能会删除或修改数据库中的任何数据。还有一个事实是,您将密码存储为纯文本。您应该学习如何参数化SQL查询,以及如何散列密码。很抱歉,没有更具体一点。我想在登录窗口表单中使用文本框输入用户名和密码后,在名为login的按钮中,可以检查文本框中的数据是否存在于数据库中,如果存在,则可以向我显示一条带有Welcome+user的消息(基于我在用户角色数据库中的列位置)并在登录成功后传递到操作。如果没有,我捕获了一个异常,并在日志记录失败时显示一条自定义消息。关于使用参数和散列的学习,谢谢,我最近开始使用vb.net和sql server编程,但是,我将继续学习您的建议。天哪,sql注入洞,蝙蝠侠!而纯文本密码也没用。