[RESOLVED] DataReader error...SQL connection problem
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:
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
My display button also follows a similar format in using the SQL connection:
Code:
disQuery.Connection = localConnection
disQuery.CommandText = "SELECT * FROM data"
disQuery.ExecuteScalar()
I've tried to insert this after the ExecuteScalar command:
Code:
localConnection.Close()
localconnection.Open()
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.
Any suggestions? Thank You! :)
Re: DataReader error...SQL connection problem
There can only be one datareader open on a connection at a time. If you need a second open a new connection for that datareader and close it (the connection) after you get the data.
Re: DataReader error...SQL connection problem
Does that mean I need to make something like a "localconnection2"?
Re: DataReader error...SQL connection problem
I got it working! I just made a new MySqlConnection variable. Thanks! Haha.