c# - Crystal Reports not selecting any records when I add a parameter to the report -


i'm using crystal reports inside of visual studio 2010 asp.net.

i've got dataset pulls data database, , seems load report fine. when view report in browser, records load correctly.

i have add parameter user enter in order filter out entries in report. problem when add sort of parameter report, viewer can't find records. before selection wizard.

i added drop down list parameter containing numbers 1, 2, , 3. without in selection expert shouldn't affect anything. whatever reason, when in report no records selected. delete parameter works again.

i'm adding parameter , values through field explorer if makes difference.

the odd thing is implementation worked when had report pull data directly database, instead of creating dataset first. reason can't use implementation kept asking database login information. when predefined information. switched dataset avoid login prompt.

i'm figuring there has wrong dataset implementation. relevant code here:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using crystaldecisions.crystalreports.engine; using crystaldecisions.shared; using system.data; using system.data.common; using system.data.sqlclient; using system.configuration; using microsoft.practices.enterpriselibrary.data;   public partial class reportpage : system.web.ui.page {      private reportdocument rpt;     private string mappath;      protected void page_load(object sender, eventargs e)     {          if (!page.ispostback) // if page loaded first time         {              mappath = "crystalreport1.rpt";             configurecrystalreport();          }      }      private void configurecrystalreport() // creates instance of report file , binds viewer on page     {          mydataset ds = new mydataset();          mydatasettableadapters.mytabletableadapter dsta = new mydatasettableadapters.mytabletableadapter();         dsta.fill(ds.mytable);          // initializing report file         rpt = new reportdocument();         string reportpath = server.mappath(mappath);         rpt.load(reportpath);          datatable dt = ds.mytable;         response.write("<script>alert('table has "+ dt.rows.count.tostring() +" rows');</script>");         rpt.setdatasource(dt);           // binding report file report viewer on page         crystalreportviewer1.reportsource = rpt;         crystalreportviewer1.toolpanelview = crystaldecisions.web.toolpanelviewtype.parameterpanel;         crystalreportviewer1.hastogglegrouptreebutton = false;      } 

the response.write makes alert pops on page stating how many rows in table being sent report. counts correctly, know data being sent report, isn't selecting of it.

i have no idea why isn't selecting anything.

edit: after quick testing looks can add parameter list without breaking report. it's when put actual parameter element on page, or when use part of selection expert report fails load rows.

in other words, report works when doesn't bring parameter prompt.

edit 2: tried changing dataset code in order have connect database. thought using datasets avoid that... saw on tutorial video.

the code here:

        string sconnectionstring;         sconnectionstring = "password=myp@ssw0rd*;user id=sa;" + "initial catalog=databasename;" + "data source=servername";         sqlconnection conn = new sqlconnection(sconnectionstring);         conn.open();         sqldataadapter sda = new sqldataadapter("select * mytable", conn);         conn.close();          mydataset ds = new mydataset();          sda.fill(ds, "mytable");         // initializing report file         rpt = new reportdocument();         string reportpath = server.mappath(mappath);         rpt.load(reportpath);          rpt.setdatasource(ds); 

and after of that: nothing. still loads of data table if there no parameters @ work. add parameter (to page, or part of selection expert) no records load.

edit 3: i've tried passing in parameter programatically this:

rpt.setparametervalue("par1", 1); 

interestingly, did load of data in dataset... until passed new parameter. no records loaded, after set parameter 1. seems once viewer has handle parameter drops of records.

i don't know now. far can tell, problem rpt.setdatasource() or crystalreportsviewer1.reportsource = rpt.

edit 4: user4663200 pointed out there's issue mappath being null when page posted back. tried fixing it, ran new error, popup shows , says 'please wait while document being processed.' forever. looked error , multiple sources told me transfer loading code page_init() page_load().

the important part error somehow cause when page posts after user enters parameter. apparently page have loaded fine if didn't post back.

i tried implementing simpler version of code in page_init, doesn't work, there's still unending load popup.

here's code:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; using crystaldecisions.crystalreports.engine; using crystaldecisions.shared; using system.data; using system.data.common; using system.data.sqlclient; using system.configuration; using microsoft.practices.enterpriselibrary.data;      private reportdocument rpt; private mydataset ds;  protected void page_init(object sender, eventargs e)     {          if (!page.ispostback)         {              ds = new mydataset();               mydatasettableadapters.mytabletableadapter dsta = new mydatasettableadapters.mytabletableadapter();              dsta.fill(ds.mytable);             // initializing report file             rpt = new reportdocument();             string reportpath = server.mappath("myreport.rpt");             rpt.load(reportpath);             session.add("dataset", ds);             session["dataset"] = ds;              rpt.setdatasource(ds);              crystalreportviewer1.reportsource = rpt;          }         else         {              ds = (mydataset)session["report"];             rpt = new reportdocument();             string reportpath = server.mappath("myreport.rpt");             rpt.load(reportpath);             rpt.setdatasource(ds);             crystalreportviewer1.reportsource = rpt;          }      } 

the issue other solutions call report saved in session, happen, sessionstate needs set "inproc" mode. can't take website off of "stateserver" mode. tried workaround saving dataset in session, , binding new report each time. didn't work either.

edit 4.5 tried changing sessionstate inproc, , still doesn't work. when make report what's being saved in session.

edit 4.75 tried putting breakpoint in page_init(), , revealed interesting things.

i see session["report"]; correctly being saved during initial run through code.

but after entering parameter watched page_init() again, , when tried doing rpt = (reportdocument)session["report"]; in session["report"] null. threw lots of null exceptions, these visible in breakpoint debugger, never seemed come during normal run. i'm pretty sure that's why keeps loading forever after post back.

so problem post after entering parameter causes data in session lost.

edit 4.825: can disregard previous edit. commented out code:

    protected void page_unload(object sender, eventargs e)     {         try         {             rpt.close();             rpt.dispose();         }         catch { }     } 

after getting rid of code, looked through session["report"] variable again , no longer null.

interestingly, page_unload being called before getting parameter entry. if rpt.close(); dumping references rpt, it's if session variable acting pointer, instead of storing actual rpt object. when rpt disposed(), session["report"] appears null pointer.

so right stuff being passed around... still has infinite 'document processing' screen.

edit 5: got work.

it turns out sessions solution, couldn't find implementations of it.

i got of relevant code here. can't copy , paste that.

here's implementation

    private reportdocument rpt;     private mydataset ds;      protected void page_init(object sender, eventargs e)     {          if (!ispostback)         {              session["report"] = null;          }          if (session["report"] == null)         {              ds = new mydataset();             mydatasettableadapters.mytabletableadapter dsta = new mydatasettableadapters.mytabletableadapter();             datatable dt = dsta.getdata();              rpt = new reportdocument();             rpt.load(server.mappath("myreport.rpt"));             rpt.setdatasource(dt);             session.add("report", rpt);             crystalreportviewer1.reportsource = rpt;             crystalreportviewer1.toolpanelview = crystaldecisions.web.toolpanelviewtype.parameterpanel;             crystalreportviewer1.hastogglegrouptreebutton = false;          }      }      protected void page_load(object sender, eventargs e)     {          if (page.ispostback)          {              rpt = (reportdocument)session["report"];             crystalreportviewer1.reportsource = rpt;             crystalreportviewer1.toolpanelview = crystaldecisions.web.toolpanelviewtype.parameterpanel;             crystalreportviewer1.hastogglegrouptreebutton = false;          }      }      protected void butreport_click(object sender, eventargs e)     {          if (session["report"] == null) // report not in session (previously loaded) load report, set params, view , place in session         {              ds = new mydataset();             mydatasettableadapters.mytabletableadapter dsta = new mydatasettableadapters.mytabletableadapter();             datatable dt = dsta.getdata();              rpt = new reportdocument();             rpt.load(server.mappath("myreport.rpt"));             rpt.setdatasource(dt);             session.add("report", rpt);             crystalreportviewer1.reportsource = rpt;             crystalreportviewer1.toolpanelview = crystaldecisions.web.toolpanelviewtype.parameterpanel;             crystalreportviewer1.hastogglegrouptreebutton = false;          }         else         {              rpt = (reportdocument)session["report"];             crystalreportviewer1.reportsource = rpt;             crystalreportviewer1.toolpanelview = crystaldecisions.web.toolpanelviewtype.parameterpanel;             crystalreportviewer1.hastogglegrouptreebutton = false;          }      } 

the big difference line: datatable dt = dsta.getdata(); before passing in entire dataset rpt. i'm not sure why, creating new datatable getdata()'s results lets report stay in session.

now report kept in session of postbacks. encountered , solved few other issues, session not resetting when user leave page , comes back.

your sql query missing clause, no matter put in parameter return of records. reason on subsequent calls fails mappath blank, create on every page_load, set if not postback. means after initial page load, mappath null, there no report pull.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -