I've got a code using SQLClient that loops though all users in a Users table inside each loop i want to preform another search in the UserOrders table, thus doing a count of all orders.
I get this error
Here is my codeHTML Code:There is already an open DataReader associated with this Command which must be closed first.
vb.net Code:
UserLists.Items.Clear() Dim connection As New SqlClient.SqlConnection(My.Settings.ConnectString) Dim command As New SqlClient.SqlCommand("SELECT * FROM Users ORDER BY PersonName", connection) connection.Open() Dim reader As SqlClient.SqlDataReader = command.ExecuteReader Dim Ops As String = "" While reader.Read Dim ID As Integer = reader("ID") Dim command2 As New SqlClient.SqlCommand("SELECT Count(ID) FROM UserOrders WHERE UserID = @ID", connection) command2.Parameters.AddWithValue("@ID", ID) Dim count = command2.ExecuteScalar Dim listitem As New ListViewItem listitem.Text = reader("Username") listitem.SubItems.Add(reader("PersonName")) listitem.SubItems.Add(count) listitem.Tag = reader("ID") UserLists.Items.Add(listitem) End While connection.Close()




Reply With Quote