I'm pretty new to c# programming and I have inherited this script I'm trying to work on.
I'm calling a procedure with 3 results sets. The first result set will always return 1 record. The second result set may return 1 or 0 records. The third result set may return 1 or 0 records.
SqlCommand cmd = new SqlCommand("MyProc", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@param1", param1));
cmd.Parameters.Add(new SqlParameter("@param2", param2));
pageData = cmd.ExecuteReader();
while (pageData.Read()){
// Do some stuff here
}
Response.Write("HERE");
pageData.NextResult();
while (pageData.Read()){
// Do some stuff here
}
Response.Write("HERE2");
pageData.NextResult();
while (pageData.Read()){
Response.Write("HERE3");
}
In my test case, the first record set returns 1 result, the second one 0 and the third 1. In this case, it outputs the first "HERE", but skips the second and third.
I need to skip the second set if there are 0 results for it and go to the third
usingstatements to dispose of your reader.