Hi, I am creating an login page connected to a database. I am using access ODB. the problem is, if the user makes an wrong input, and the invalid data message box appeared, when typing the data again, and press ok, the following exeption occured:
Not allowed to change the 'ConnectionString' property. The connection's current state is open.

here is the code.

much needed help, thank you.

Public Class LoginForm1

    Dim DbCon As New OleDb.OleDbConnection
    Dim dbUp As New OleDb.OleDbCommand
    Dim Read As OleDb.OleDbDataReader
   



    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        DbCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\unpw.mdb"
        DbCon.Open()
        dbUp.Connection = DbCon
        dbUp.CommandType = CommandType.Text
        dbUp.CommandText = "Select * from UNPW where Username=UsernameTextBox.Text and Password=PasswordTextBox.Text "
        dbUp.Parameters.Add("Username", Data.OleDb.OleDbType.Variant)
        dbUp.Parameters.Add("Password", Data.OleDb.OleDbType.Variant)
        dbUp.Parameters("Username").Value = UsernameTextBox.Text
        dbUp.Parameters("Password").Value = PasswordTextBox.Text
        Read = dbUp.ExecuteReader
        With Read
            If .Read Then
                Contacts.Show()
                Me.Close()


            Else
                UsernameTextBox.Clear()
                PasswordTextBox.Clear()
                MessageBox.Show("Invalid Username or Password")
                UsernameTextBox.Focus()

            End If
        End With
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        If MessageBox.Show("Do you want to exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        Else
        End If
    End Sub

{"COM object that has been separated from its underlying RCW cannot be used."}

Read = dbUp.ExecuteReader

i'm confused. it should work..

Edited 5 Years Ago by onat12`: n/a

This question has already been answered. Start a new discussion instead.