feesu
asked on
ADO.NET - sqlDataReader.NextResult()
Hi Experts,
I have got an sqlDataReader DR that holds several result sets.
I wish to bind each result set to a different grid.
I used the below but I am getting errors. I am sure I did something wrong:
I have got an sqlDataReader DR that holds several result sets.
I wish to bind each result set to a different grid.
I used the below but I am getting errors. I am sure I did something wrong:
With grd_1
.DataSource = DR
End With
With grd_2
DR.NextResult()
DR.Read()
.DataSource = DR
End With
Why are you using DR.Read()?
Remove that line and try again. Also post the error that you are getting.
Remove that line and try again. Also post the error that you are getting.
ASKER
krunal,
I did what you said and got the following error on the NextResult line:
Invalid attempt to call NextResult when reader is closed.
I did what you said and got the following error on the NextResult line:
Invalid attempt to call NextResult when reader is closed.
k.. your salconnection needs to be open while you are reading the datareader,
refer this link for details,
http://www.dotnetjohn.com/articles.aspx?articleid=23
refer this link for details,
http://www.dotnetjohn.com/articles.aspx?articleid=23
your code should be in between,
objConn.Open()
...
objConn.Close()
where objConn is the object of your SqlConnection
objConn.Open()
...
objConn.Close()
where objConn is the object of your SqlConnection
ASKER
Find below the function that returns my DR from the stored procedure, what exactly should be changed?
Public Function lid_report_weekly_get(ByVa l valueDate As Date) As SqlDataReader
Dim CN As New SqlConnection(System.Confi guration.C onfigurati onManager. Connection Strings("S iteSqlServ er").ToStr ing)
Dim CMD As New SqlCommand("lid_report_wee kly_get", CN)
CMD.CommandType = CommandType.StoredProcedur e
Dim P As New SqlParameter
P = New SqlParameter("@today", SqlDbType.DateTime)
P.Value = valueDate
CMD.Parameters.Add(P)
CN.Open()
Dim DR As SqlDataReader = CMD.ExecuteReader(CommandB ehavior.Cl oseConnect ion)
Return DR
End Function
Public Function lid_report_weekly_get(ByVa
Dim CN As New SqlConnection(System.Confi
Dim CMD As New SqlCommand("lid_report_wee
CMD.CommandType = CommandType.StoredProcedur
Dim P As New SqlParameter
P = New SqlParameter("@today", SqlDbType.DateTime)
P.Value = valueDate
CMD.Parameters.Add(P)
CN.Open()
Dim DR As SqlDataReader = CMD.ExecuteReader(CommandB
Return DR
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try the below code
Open in new window