sql server - Asp.net calling SQL stored procedure that returns MultipleRecordset with heading -
i have stored procedure below
select 'result first' select name, starttime, endtime, datediff( minute , starttime, endtime) gap, id ,type mytable t1 id in (select id idtable starttime between @min , @max) , name = 'resultfirst' order id desc select 'result second' select name,min(starttime) starttime, max(endtime) endtime myt2 (id = @id ) group name select 'result third' select name, min(starttime) starttime, max(endtime) completedtime, datediff(mi,min(starttime),max(endtime)) diff myt3 count(*) success (id = @id2) group name
the sp returns multiple tables-formats respective heading. have code in asp.net mvc have context above db. tried create class manually matching above result set (though looks odd) , try execute sp below
var lrdetails = this.context.database.sqlquery<mycustomeclass>("exec myresultsetsp @number", param).tolist(); foreach (var item in lrdetails) { var = item; console.writeline(i); }
but "result first" , nothing else. tried alternate below output same again "result first". did execute , confirm sp in ssms , getting correct result tables.
var cmd = this.context.database.connection.createcommand(); cmd.commandtype = commandtype.storedprocedure; cmd.commandtext = "myresultsetsp"; try { this.context.database.connection.open(); // run sproc var reader = cmd.executereader(); arraylist rowlist = new arraylist(); while (reader.read()) { object[] values = new object[reader.fieldcount]; reader.getvalues(values); rowlist.add(values); } reader.nextresult(); } { this.context.database.connection.close(); }
how multiple result set either can loop through or can cast respective asp.net class tried mapped output of sp. hope if can design kind of thing sp me map datatype correctly in asp.net. tried below more details
datatable dt = new datatable(); dt.load(reader); int icolcount = dt.columns.count; foreach (datarow dr in dt.rows) { (int = 0; < icolcount; i++) { var item = dr[i]; } }
the icolcount 1 , item "result first" only. suspect custom class wrote manually mycustomeclass may not mapping correctly results-set. or if tolist() @ end of query execution ok. data set issue single item "result first"
using (sqldataadapter da = new sqldataadapter(cmd1)) { dataset dataset = new dataset(); da.fill(dataset); var ds = dataset; foreach (datarow dr in dataset.tables[0].rows) { foreach (var item in dr.itemarray) { string myvar = item.tostring(); console.writeline(myvar); //here 1 loop "result first" } } }
Comments
Post a Comment