Hi, I have been using a listbox to insert records into the database.
But I get this error when I try to add more than one records into the database :
'There is already an open DataReader associated with this Command which must be closed first.'
Can someone help me on this?
But I get this error when I try to add more than one records into the database :
'There is already an open DataReader associated with this Command which must be closed first.'
Can someone help me on this?
Code:
database.OpenConn()
For j As Integer = 0 To ListBox1.Items.Count - 1
Dim strSQL = "Select * FROM table1 where Name = '" & ListBox1.Items(j).ToString() & "'"
Dim dr as SqlDataReader = db.ExecuteQuery(strSQL)
While dr.Read()
Dim ID = dr("ID").ToString()
End While
Next
dr.Close()
database.CloseConn()
database.OpenConn()
Dim strSQL2 = "INSERT INTO table2 Values (" & ID & ")"
database.ExecuteUpdate(strSQL2)
dr.Close()
database.CloseConn()
Comment