Why second result is empty

  • Thread starter Thread starter Jennie.jiang
  • Start date Start date
J

Jennie.jiang

Hi,

I have a stored procedure which returns two resultsets.
I used SqlDataReader to retrieve the result as following:

SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand("MyStoredProcedure", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
//access data
}
if(dr.NextResult())
{
while(dr.Read())
{
//access data
}
}
dr.Close();
con.Close();

The return value of dr.NextResult() is true, but it is empty.

I'm sure there is data in second resultset. Is anything wrong in my code?
Any reply is appretiated.
 
SqlDataReader.NextResult
true if there are more result sets; otherwise, false.

SqlDataReader.Read
true if there are more rows; otherwise, false.

Are you sure your stored procedure is returning
rows for the second resultset?

Try executing your stored procedure in SQL Analyzer.
 
Thanks for the reply.
I executed it in the SQL Analyzer and it returns what I expect.
But dr.Read() returns false.
 
Hi, Jennie

Can you show your simplified Accessing data code for next result

Or do like the following
if (dr.NextResult()

Debug.WriteLine("Has Records in Second Set: " + dr.Read()); //Window
//Response.Write(("Has Records in Second Set: " + dr.Read()); //We
/
//Access Dat
*


Bin Song, MC

----- Jennie.jiang wrote: ----

Thanks for the reply
I executed it in the SQL Analyzer and it returns what I expect
But dr.Read() returns false
 
Thanks so much. :-)
It works now, but I really don't understand, because I did not change
anything and it works now. No clue at all. :-(

Thank you guys again.
 
Back
Top