Question A login form using a database

formlesstree4

Well-known member
Joined
Jul 17, 2008
Messages
61
Programming Experience
1-3
Well, I've been trying for about 3 weeks now (sad, I know) to get a login form read from a database. I've tried a lot of things, and so far, nothing works. This is what I have so far:

VB.NET:
Expand Collapse Copy
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim dr As SqlCeDataReader = cmd.ExecuteReader
        cmd = New SqlCeCommand("SELECT Username,Password FROM users WHERE Username ='" & txtUser.Text & "' AND Password ='" & getMD5Hash(txtPassword.Text) & "')", con)
        con.Open()
        cmd.ExecuteNonQuery()
        Try
        Catch ex As InvalidOperationException
            MsgBox(ex.Message)
        End Try
        Try
            If dr.Read = False Then
                MessageBox.Show("Authentication Failed...")
            Else
                MessageBox.Show("Login Successful...")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
        If con.State <> ConnectionState.Closed Then
            con.Close()
        End If
    End Sub

My problem is, I don't know if it connects or even checks. Cause this is the error I get:
VB.NET:
Expand Collapse Copy
"Object reference not set to an instance of an object."

Any help would be nice.
 
Try this ...

VB.NET:
Expand Collapse Copy
Dim dt As New DataTable()

        Try
            Dim conn As New SqlCeConnection(connStr)
            conn.Open()

            Dim adapter As SqlCeDataAdapter = New SqlCeDataAdapter(query, conn)
            adapter.Fill(dt)
            conn.Close()

            If dt.Rows.Count = 1 Then
                MessageBox.Show("Login Successful...")
            Else
                MessageBox.Show("Authentication Failed...")
            End If

        Catch ex As Exception

        End Try
 
When I click Ok, nothing happens, so I run it in debug mode. When debugging the program, I get this error:

VB.NET:
Expand Collapse Copy
A first chance exception of type 'System.TypeInitializationException' occurred in System.Transactions.dll

It won't highlight any lines either....

Before you ask,
VB.NET:
Expand Collapse Copy
Dim adapter As SqlCeDataAdapter = New SqlCeDataAdapter(query, conn)
I put my query in the place of where it said query. I had to change conn to con, cause that's how I declare it (In my Public class).

Go ahead and close this, I solved the problem :)
 
Back
Top