c# - MVC 4 - Reporting Service and Stored Procedures -


i'm using mvc4 , entity framework in order develop intranet web app , 1 of requirements app able create reports. i'm using reporting service that.

in report file (.rdlc), have table supposed contain records have in table "persons". have created stored procedure gets persons db , action allow downloading of report.

th thing is, have no idea how tell action data source stored procedure.

here action :

public actionresult personreport() {      reportviewer personreportviewer = new reportviewer();      list<reportparameter> reportparameters = new list<reportparameter>();      reportparameters.add(new reportparameter("title", "test"));      personreportviewer.localreport.setparameters(reportparameters);      personreportviewer.processingmode = processingmode.local;     personreportviewer.localreport.reportembeddedresource =         httpcontext.server.mappath(".") + "\\reporting\\templates\\"         + "personreport.rdlc";      byte[] bytearray = personreportviewer.localreport.render("pdf");      response.clearheaders();     response.addheader("content-disposition",           "attachment; filename=\"" + datetime.now + "_title_" + "\"");     response.addheader("content-transfer-encoding", "binary");     response.binarywrite(bytearray);     response.flush();     response.end();      return redirecttoaction("index"); } 

and here stored procedure :

alter procedure dbo.getallpersons   begin      set nocount on      select *  bm_persons;  end 

any idea how that? lot.

you need run procedure , pass result reportviewer.
how you not possible answer @ moment. using plain old ado.net connect database, or entity framework, or nhibernate etc...

your stored procedure return collection of results, assign variable , pass reportviewer. or have method getallpersons returns array or ilist<t> or other suitable type , can use outside scope of method.

given you're using ef in order set of results stored procedure need method similar have taken the answer referred in comment:

public static dataset executestoredprocedure(objectcontext db,                                               string storedprocedurename,                                               ienumerable<sqlparameter> parameters) {     var connectionstring =          ((entityconnection)db.connection).storeconnection.connectionstring;     var ds = new dataset();      using (var conn = new sqlconnection(connectionstring))     {         using (var cmd = conn.createcommand())         {             cmd.commandtext = storedprocedurename;             cmd.commandtype = commandtype.storedprocedure;             foreach (var parameter in parameters)             {                 cmd.parameters.add(parameter);             }              using (var adapter = new sqldataadapter(cmd))             {                 adapter.fill(ds);             }         }     }      return ds; } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -