none
Trying to Validate information between textbox and Database RRS feed

  • Question

  • I am creating a login form that will check for non entered data. That all works fine. Though when it gets to the database query part it seems to break almost instantly. I believe I coded everything right  though I'm leaning towards the notion that I missed something. Here is the coding so far.

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

            If String.IsNullOrEmpty(txtUser.Text) And String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter login information", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.BackColor = Color.Red
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtUser.Text) Then

                MsgBox("Please enter User Name", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.Clear()
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter Password", MsgBoxStyle.Critical, "Validation")
                txtPass.BackColor = Color.Red
                txtPass.Focus()

            Else

    The Underlined and bolded text is where the exception is being thrown. The exception states that the format of the initialization string does not conform to specification starting at index 34.
                Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;C:\Users\bruce\Documents\PData.mdb_be.accdb")

                Dim cmd As OleDbCommand = New OleDbCommand( _
                                          "SELECT * FROM Passwords WHERE User Name= '" & _
                           txtUser.Text & "' and Password = ' " & txtPass.Text & "'", con)
                con.Open()
                Dim sdr As OleDbDataReader = cmd.ExecuteReader()

                If (sdr.Read() = True) Then
                    Me.Hide()
                    ADI.Show()
                Else
                    MessageBox.Show("Invalid user name or Password!")
                    txtUser.Clear()
                    txtPass.Clear()
                    txtUser.Focus()
                End If
            End If
        End Sub

    I hope someone can help me shed some light on this issue.

    Thank You


    • Edited by deagonphi Tuesday, May 28, 2013 11:50 AM
    Wednesday, May 22, 2013 2:10 PM

All replies

  • I am creating a login form that will check for non entered data. That all works fine. Though when it gets to the database query part it seems to break almost instantly. I believe I coded everything right  though I'm leaning towards the notion that I missed something. Here is the coding so far.

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

            If String.IsNullOrEmpty(txtUser.Text) And String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter login information", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.BackColor = Color.Red
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtUser.Text) Then

                MsgBox("Please enter User Name", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.Clear()
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter Password", MsgBoxStyle.Critical, "Validation")
                txtPass.BackColor = Color.Red
                txtPass.Focus()

            Else


               Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;C:\Users\bruce\Documents\PData.mdb_be.accdb")

                Dim cmd As OleDbCommand = New OleDbCommand( _
                                          "SELECT * FROM Passwords WHERE User Name= '" & _
                           txtUser.Text & "' and Password = ' " & txtPass.Text & "'", con)
                con.Open()
                Dim sdr As OleDbDataReader = cmd.ExecuteReader()

                If (sdr.Read() = True) Then
                    Me.Hide()
                    ADI.Show()
                Else
                    MessageBox.Show("Invalid user name or Password!")
                    txtUser.Clear()
                    txtPass.Clear()
                    txtUser.Focus()
                End If
            End If
        End Sub

    I hope someone can help me shed some light on this issue. If there is no issue with it please let me know for their may be an issue that I have to resolve internally.

    Thank You

    The Underlined and bolded text is where the exception is being thrown. The exception states that the format of the initialization string does not conform to specification starting at index 34.



    • Edited by deagonphi Tuesday, May 28, 2013 11:49 AM
    Friday, May 24, 2013 2:01 PM
  • I am creating a login form that will check for non entered data. That all works fine. Though when it gets to the database query part it seems to break almost instantly. I believe I coded everything right  though I'm leaning towards the notion that I missed something. Here is the coding so far.

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

            If String.IsNullOrEmpty(txtUser.Text) And String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter login information", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.BackColor = Color.Red
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtUser.Text) Then

                MsgBox("Please enter User Name", MsgBoxStyle.Critical, "Validation")
                txtUser.BackColor = Color.Red
                txtPass.Clear()
                txtUser.Focus()

            ElseIf String.IsNullOrEmpty(txtPass.Text) Then

                MsgBox("Please enter Password", MsgBoxStyle.Critical, "Validation")
                txtPass.BackColor = Color.Red
                txtPass.Focus()

            Else


                Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;C:\Users\bruce\Documents\PData.mdb_be.accdb")

                Dim cmd As OleDbCommand = New OleDbCommand( _
                                          "SELECT * FROM Passwords WHERE User Name= '" & _
                           txtUser.Text & "' and Password = ' " & txtPass.Text & "'", con)
                con.Open()
                Dim sdr As OleDbDataReader = cmd.ExecuteReader()

                If (sdr.Read() = True) Then
                    Me.Hide()
                    ADI.Show()
                Else
                    MessageBox.Show("Invalid user name or Password!")
                    txtUser.Clear()
                    txtPass.Clear()
                    txtUser.Focus()
                End If
            End If
        End Sub

    I hope someone can help me shed some light on this issue.

    Thank You

    Hi

    Please share the error you are getting and the line of code where you get the error.

    If you place breakpoints and run the code in debug mode you can get the location easily

    Cheers

    shasur


    http://www.vbadud.blogspot.com http://www.dotnetdud.blogspot.com

    Monday, May 27, 2013 4:53 AM
  • I have added a statement to the original post stateing where the exception is getting thrown.
    Tuesday, May 28, 2013 11:56 AM