I am trying to run a simple query that returns three columns but am running into an error stating that the data does not exist though I am quite certain it does.
This is the section of code in question.
cmd.CommandText = "SELECT school.id, school.city, school.state
FROM school,city
WHERE school.name = '" & SchoolLb.SelectedItem & "'
AND city.name = '" & CityLb.SelectedItem & "';"
'MessageBox.Show(cmd.ExecuteScalar)
myReader = cmd.ExecuteReader
profileSchool = myReader(0)
profileCity = myReader(1)
profileState = myReader(2)
The School list box is populated with schools located in the city that is currently selected in the city list box, so they match up. When I remove the comment tag from MessageBox.Show(cmd.ExecuteScalar) the ExecuteScalar runs and returns a message showing the ID of the correct record. However when using cmd.ExecuteReader I get the error mentioned above.
Thanks for looking.
You need to execute the reader and then advance it to the next record by using
reader.Read():