I am working on a vb windows form application with several connected forms. Its used to manipulate a MySQL database. One of the sub-forms has the following code snippet:
1 myCommand.Connection = conn
2 myCommand.CommandText = SQL1
3 myAdapter.SelectCommand = myCommand
4 myAdapter.Fill(myData1)
5 ComboBox4.DataSource = myData1
6 ComboBox4.DisplayMember = "area_name"
7 ComboBox4.ValueMember = "area_name"
This works fine the first time I access the form, but if I go back to the main form then try to access the same sub-form again, I get a runtime error at line 4 saying "Argument NullException was undandled: Key cannot be null. Parameter name: key".
I tried disposing of myData1 (a data table) after use, but that still didn't work. Note that all the variables are declared as New in the beginning. Help?