c# - Using DataTable.Load() method is not working in case two resultsets returned by DataReader -
with motive of enhancing performance trying eliminate dataset use & implement datareader. here oracle procedure returning 2 refcursors & when loading first recordset in first datatable, next 1 never gets loaded.
sample code looks :
dataset ds = new dataset(); using (oracleconnection db = new oracleconnection(constring)) { try { using (oraclecommand mycom = new oraclecommand()) { mycom.commandtext = "mypkg.pr_mysp"; mycom.connection = db; mycom.commandtype = commandtype.storedprocedure; mycom.parameters.add("ref_list1", oracledbtype.refcursor).direction = parameterdirection.output; mycom.parameters.add("ref_list2", oracledbtype.refcursor).direction = parameterdirection.output; //mycom.fetchsize = mycom.fetchsize * 64; db.open(); using (oracledatareader reader = mycom.executereader()) { datatable custmaplist = new datatable("dtcustmaplist"); custmaplist.load(reader); reader.nextresult(); // post second datatable doesnot getting populated datatable custmapsublist = new datatable("dtcustmapsublist"); custmapsublist.load(reader); ds.tables.add(custmaplist); ds.tables.add(custmapsublist); } } } catch (exception ex) { returnstring += "error, " + ex.message; }
i know there alternative methods looping using while(reader.read()) ... & using reader.nextresult() work, in case have change many other codes think can avoided if above works fine.
appreciate response.
looking @ reference source datatable.load
method clear method calls nextresult()
before exiting, don't need it.
.... if(!reader.isclosed && !reader.nextresult()) reader.close(); ....
and way, there no need go source. msdn says:
the load method consumes first result set loaded idatareader, , after successful completion, sets reader's position next result set, if any.
so need remove line
// reader.nextresult(); // post second datatable doesnot getting populated
Comments
Post a Comment