I suspect the problem is that you are storing your
OleDbCommand
object in a class-level field, and reusing it across methods.
Change your code to create the command instance when you need it, and wrap it in a
Using
block, and your error will almost certainly go away.
Private Sub cmbCategory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCategory.SelectedIndexChanged
Using cons As New OleDb.OleDbConnection(conSTR)
Using cmd As New OleDb.OleDbCommand()
cmd.Connection = cons
cmd.CommandText = "SELECT CategoryName, CatPercent FROM Category WHERE CategoryName = @cn"
cmd.Parameters.AddWithValue("cn", cmbCategory.Text)
cons.Open()
Using rdr As OleDb.OleDbDataReader = cmd.ExecuteReader()
If rdr.Read() Then
txtCategory.Text = rdr("CategoryName").ToString
numCategory.Text = rdr("CatPercent")
Else
MessageBox.Show("NO DATA FOUND", "CATEGORY", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Using
End Using
End Using
End Sub