Hi! I'm having trouble with my connection between VB and MySQL. I've made a program that displays data in a list box that it gets from my database. I have a Button that when clicked, displays the data in a listbox. When I try to delete part of the data, this error shows up:
"There is already an open DataReader associated with this Connection which must be closed first."
Here is the code for the delete button:
My display button also follows a similar format in using the SQL connection:Code:Private Sub Delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Delete.Click Dim delQuery As New MySqlCommand Dim index As Integer index = DataBox.SelectedIndex DataBox.Items.RemoveAt(index) delQuery.Connection = localConnection delQuery.CommandText = "DELETE FROM `temp_data`.`data` WHERE `idx` = '" + idx(index) + "'" delQuery.ExecuteScalar() End Sub
I've tried to insert this after the ExecuteScalar command:Code:disQuery.Connection = localConnection disQuery.CommandText = "SELECT * FROM data" disQuery.ExecuteScalar()
This works but I'm afraid it might cause my other functions to not work properly. I have another running thread that constantly sends data to the database every x minutes. I'm afraid that when I click the display or delete button, the program may fail.Code:localConnection.Close() localconnection.Open()
Any suggestions? Thank You!![]()


Reply With Quote
