can you please show code for this
WTPTableAdapter.sp_ScalarQ
or put a breakpoint here and "step into" here when prg hits this to find where the exact problem is...
Main Topics
Browse All TopicsI'm trying to set the text of a lable to the count returned from a stored procedure but I get this error:
"There is already an open DataReader associated with this Command which must be closed first."
Visual Studio sort of "highlights" in gray a few lines that I assume are causing the problem, but I don't know how to close the offending open DataReader.
In the Form_Load, this line is highlighted:
"cbCaseManagers.DataSource
This whole sub for a ComboBox is highlighted:
Private Sub cbCaseManagers_SelectedInd
Try
Me.WTPTableAdapter.FilterB
Catch ex As System.Exception
System.Windows.Forms.Messa
End Try
End Sub
This is the line throwing the error:
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I put a breakpoint there and the program loops through it a couple of times then stops with the open DataReader exception right there on the lblMandatory.Text = "Count..." line in the WTPDataGridView_RowStateCh
WTPTableAdapter.sp_Sca
I'm not sure how to tell the procedure to use the connection string from the app.config so I put it in the code.
I haven't modified my connection string yet to try your method because I wasn't sure how much I would have to change my code to implement it. I'm just learning, so the more changes I have to make to something the more likely I'll either break it or get to a point that I don't understand what it's doing and can't maintain it.
So, for now I tried doing it like this. It seems to work but this is all to count the results of only one question. I have 43 questions to report the counts of so this doesn't look like the best solution:
Well, using the method in the code box just above, I don't have the exception problem because I'm opening a new connection anyway.
If I just add "MultipleActiveResultSets=
lblMandatory.Text = "Count of Mandatory: " & CStr(WTPTableAdapter.sp_Sc
...inst
I have no idea! It is really hard for me to follow you when I don't have the complete picture.
>>I don't have the exception problem because I'm opening a new connection anyway.
Don't forget that ADO.net is pooling the connections. Just add the additional parameter to all your connection strings and your problem will be solved.
I added "MultipleActiveResultSets=
"lblMandatory.Text = "Count of Mandatory: " & CStr(WTPTableAdapter.sp_Sc
and it works.
Now I think I can add a stored procedure for each of the 43 questions (ugh!) and a similar line to run each of them unless there is a better way.
Could you elaborate on that a little? Like I said, I'm just learning this stuff. If there's a simple solution I'd like to learn how to do it.
Are you saying that it's possible to return the counts of all the questions in a single query?
Right now the stored procedure (in comment ID:25569820) is just returning the count of "Y" values in the "Mandatory" column. There are 42 additional columns I need to do the same with. (count "Y"s currently displaying in the GridView as a result of the filters selected by the combo boxes)
it is not really clear to me what you are trying to do! Remember that we don't have access to your stuff.
do you mean that Mandatory have 42 different values? that would give you this:
SELECT Mandatory , COUNT(1)
FROM WTP
WHERE (OneStop LIKE @OneStop) AND (CaseManagerLName LIKE @CaseManagerLName) AND (ReviewDate BETWEEN @FromDate AND @ToDate) AND
(ReviewerName LIKE @ReviewerName) AND (ReviewType LIKE @ReviewType)
group by Mandatory
or if you have 42 fields like mandatory, you could union them:
SELECT 'Mandatory', COUNT(1)
FROM WTP
WHERE (OneStop LIKE @OneStop) AND (CaseManagerLName LIKE @CaseManagerLName) AND (ReviewDate BETWEEN @FromDate AND @ToDate) AND
(ReviewerName LIKE @ReviewerName) AND (ReviewType LIKE @ReviewType) AND (Mandatory LIKE 'Y')
UNION
SELECT 'YourSecondField', COUNT(1)
FROM WTP
WHERE (OneStop LIKE @OneStop) AND (CaseManagerLName LIKE @CaseManagerLName) AND (ReviewDate BETWEEN @FromDate AND @ToDate) AND
(ReviewerName LIKE @ReviewerName) AND (ReviewType LIKE @ReviewType) AND (YourSecondField LIKE 'Y')
UNION
SELECT 'YourThirdField', COUNT(1)
FROM WTP
WHERE (OneStop LIKE @OneStop) AND (CaseManagerLName LIKE @CaseManagerLName) AND (ReviewDate BETWEEN @FromDate AND @ToDate) AND
(ReviewerName LIKE @ReviewerName) AND (ReviewType LIKE @ReviewType) AND (YourThirdField LIKE 'Y')
UNION
....
The database contains records created by the submission of a questionaire like form that asks for FirstName, LastName (unimportant), CaseManager, Reviewer, OneStop, FromDate, ToDate, ReviewType. Those six fields are used as parameters in the stored procedure to filter the data displayed in the GridView. In addition to those fields are 43 questions. Each question is a field or column in the record. "Mandatory" is one of the 43 question columns. The question can be answered either "Y" or "N" so when the GridView is filtered using the combo boxes the stored procedure counts the displayed "Y" answers in that one column (of 43), currently only "Mandatory".
Yes, I think the UNION query is exactly what I would need. Possibly two of them because I may also need to count the "N" responses to each question.
Yes, each part of the UNION query would be identical except for the 'YourSecondField', 'YourThirdField' would be different for each, just like you've shown.
Business Accounts
Answer for Membership
by: emoreauPosted on 2009-10-13 at 18:00:18ID: 25566295
have a look at http://www.emoreau.com/Ent ries/Artic les/2006/1 1/MARS-and - Asynchron ous-ADONet .aspx