c# - Get number of result sets from a SqlDataReader -
i have sql server stored procedure returns multiple results. body of stored procedure might this:
select * tablea; select * tableb; select * tablec;
in case, stored procedure returns 3 result sets. other stored procedures might return, e.g., 1, 0, or number of result sets. each result set might contain 0 or more rows in it. when loading these, need call idatareader.nextresult()
navigate between result sets.
how can reliably count of result sets (not row counts) in c#?
use datareader.nextresult
advance reader next result set.:
using (var con = new sqlconnection(properties.settings.default.connectionstring)) { using (var cmd = new sqlcommand("select * tablea; select * tableb; select * tablec;", con)) { con.open(); using (idatareader rdr = cmd.executereader()) { while (rdr.read()) { int firstintcol = rdr.getint32(0); // assuming first column of type int32 // other fields ... } if (rdr.nextresult()) { while (rdr.read()) { int firstintcol = rdr.getint32(0); // assuming first column of type int32 // other fields ... } if (rdr.nextresult()) { while (rdr.read()) { int firstintcol = rdr.getint32(0); // assuming first column of type int32 // other fields ... } } } } } }
Comments
Post a Comment