During Loading of form I call connectpaybox to show the list in the combobox, but after that it will result in the error
"Operation is not valid due the current state of the object"
but the combobox items that was taken from the database shows. I tried
"select CAGECOST from CAGETYPE where CAGENAME like 'Normal'"
where Normal is one of the items in cagename and it works.
Private Sub Paybox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call connectpaybox()
Paybox.ComboBox2.SelectedIndex = 0
End Sub
Public Sub connectpaybox()
Dim cagename As String
Try
conn.ConnectionString = lubid
conn.Open()
'''''''''''' SQL''''''''''''''''''''
Dim sql As String = "select cagename from CAGETYPE "
Dim cmd As New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
''''''''' READ '''''''''
Dim dr As OracleDataReader = cmd.ExecuteReader()
While (dr.Read())
Paybox.ComboBox2.Items.Add(dr.GetString(0))
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
End Try
If Paybox.ComboBox2.Items Is Nothing Then
Paybox.ComboBox2.Text = "No available Unit"
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Try
conn.ConnectionString = lubid
conn.Open()
'''''''''''' SQL''''''''''''''''''''
Dim sql As String = "select CAGECOST from CAGETYPE where CAGENAME like '" + ComboBox1.Text + "'"
Dim cmd As New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
''''''''' READ '''''''''
Dim dr As OracleDataReader = cmd.ExecuteReader()
dr.Read()
cagecost = CInt(dr.Item("CAGECOST"))
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
Finally
conn.Close()
End Try
End Sub