0

I'm attempting to create a program where the login and password will be verified on an SQL database of user information. I keep getting the error "SQL Execution was unhandled" I marked the code that was causing the error in red. I'm using Visual Studio 8. Keep in mind I am pretty unsure of what I'm doing, and I am probably no where to even close to the right track.

Public Class Form1

    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        pnlLogin.Visible = False
        GroupBox1.Visible = True
        PanelSales.Visible = True



    End Sub

    Private Sub btnInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventory.Click
        ' Show or Hide the Panel contents.
        PanelInventory.Visible = True
        PanelSales.Visible = False
        PanelCustomers.Visible = False
        PanelPurchasing.Visible = False


    End Sub

    Private Sub btnCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomer.Click
        ' Show or Hide the Panel contents.
        PanelInventory.Visible = False
        PanelPurchasing.Visible = False
        PanelSales.Visible = False
        PanelCustomers.Visible = True



    End Sub

    Private Sub btnSales_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSales.Click
        ' Show or Hide the Panel contents.
        PanelInventory.Visible = False
        PanelPurchasing.Visible = False
        PanelCustomers.Visible = False
        PanelSales.Visible = True


    End Sub

    Private Sub BtnPurchasing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPurchasing.Click
        ' Show or Hide the Panel contents.
        PanelInventory.Visible = False
        PanelPurchasing.Visible = True
        PanelSales.Visible = False
        PanelCustomers.Visible = False

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub LoginBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.LoginBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.MsimsDataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'MsimsDataSet.Login' table. You can move, or remove it, as needed.
        ' Me.LoginTableAdapter.Fill(Me.MsimsDataSet.Login)
    End Sub

    Private Sub UsernameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UsernameTextBox.TextChanged
        Timer1.Start()

        Dim connection As New SqlClient.SqlConnection
        Dim command As New SqlClient.SqlCommand
        Dim adapter As New SqlClient.SqlDataAdapter
        Dim dataset As New DataSet

        connection.ConnectionString = ("Data Source=blahblahblah")
        Try
            connection.Open()
        Catch myerror As SqlClient.SqlException
            MessageBox.Show("Error Connecting to Database: " & myerror.Message)
        End Try

        Dim sqlquery = "SELECT username, password FROM Login Where username='" & UsernameTextBox.Text & "' and password='" & PasswordTextBox.Text & "'"
        command.Connection = connection
        command.CommandText = sqlquery
        'start query
        adapter.SelectCommand = command
        Dim myData As SqlClient.SqlDataReader
        myData = command.ex()
        'see if user exits. 

    End Sub

    Private Function StringtoMD5(ByVal content As String) As String
        'uses hashed password

        Dim M5 As New System.Security.Cryptography.MD5CryptoServiceProvider
        Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(content)

        ByteString = M5.ComputeHash(ByteString)

        Dim FinalString As String = Nothing

        For Each bt As Byte In ByteString
            FinalString &= bt.ToString("x2")
        Next
        Return FinalString



    End Function

End Class
2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by lolafuertes
0

For your purpose, line 89 should be

Try
    myData = command.ExecuteReader()
    If Not myData.HasRows Then
       ' Password not found
       'TODO: what you will need when the user and password does not exists in the DB
    Else
        ' Password found
        'TODO: What you will decide when the password is found
    End If
Catch ex as exception
    'TODO: Show the error
Finally
    myData.Close()
End Try

Edited by lolafuertes: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.