i am trying to iterate through the checkboxes in a groupbox to see which ones are selected so that i can insert the info into the datavase. I am getting a cast exception at the "For each ..." line - i wonder if a checkbox is something other than a control???
The exception:
System.InvalidCastException: Specified cast is not valid.
Code:
Dim chkSelected As CheckBox
[COLOR=Red]For Each chkSelected In GroupBox1.Controls[/COLOR]
chkSelected = CType(Controls.Item("chkSelected"), CheckBox)
If chkSelected.Checked = True Then
'set the Meds field of the command
updateCommand3.Parameters.Item("Meds").Value() = chkSelected.Text
'update the database
updateCommand3.ExecuteNonQuery()
End If
Next
The exception:
System.InvalidCastException: Specified cast is not valid.