c# - Why is exported report empty? -


i have empty exported report , don't know why happening this.

i have following code in 1 of methods:

    reportdocument report = new reportdocument();     report.load(pathtoreport); 

after loading successfully, set parameters using next method:

    public static void setparametervalue(reportdocument document,string parname,object value)     {         parameterfielddefinition f = document.datadefinition.parameterfields[parname];         parameterdiscretevalue v = new parameterdiscretevalue();         v.value = value;         f.currentvalues.add(v);         f.defaultvalues.add(v);         f.applydefaultvalues(f.defaultvalues);         f.applycurrentvalues(f.currentvalues);     } 

and after above call, call:

private void applynewserver(reportdocument report)     {         //initialize subreports connection first         foreach (reportdocument subreport in report.subreports)         {             foreach (table crtable in subreport.database.tables)             {                 tablelogoninfo logoninfo = crtable.logoninfo;                 logoninfo.connectioninfo.servername = "servername";                 logoninfo.connectioninfo.userid ="user";                 logoninfo.connectioninfo.password ="password";                 logoninfo.connectioninfo.integratedsecurity = false;                  crtable.applylogoninfo(logoninfo);             }         }          foreach (table crtable in report.database.tables)         {             tablelogoninfo logoninfo = crtable.logoninfo;             logoninfo.connectioninfo.servername = "servername";             logoninfo.connectioninfo.userid = "user";             logoninfo.connectioninfo.password = "password";             logoninfo.connectioninfo.integratedsecurity = false;              crtable.applylogoninfo(logoninfo);         }          verifydatabase(report);          foreach (iconnectioninfo info in report.datasourceconnections)         {             if (info.type == connectioninfotype.crqe)             {                 info.setconnection("databasename", string.empty,"user","password");             }         }     } 

and verifydatabase does:

    private void verifydatabase(reportdocument report)     {         report.setdatabaselogon(user, pwd, dbname, string.empty);         report.verifydatabase();     } 

after this, try export report:

  public bool exportreport(reportdocument reportdocument, string exporttype, string exportpath, string filename)     {         //creating full report file name          filename = filename + "." + exporttype;          //creating storage directory if not exists         if (!directory.exists(exportpath))             directory.createdirectory(exportpath);          //creating new instance representing disk file destination          //options such filename, export type etc.         diskfiledestinationoptions diskfiledestinationoptions = new diskfiledestinationoptions();         exportoptions exportoptions = reportdocument.exportoptions;          switch (exporttype)         {              case "rpt":                 {                     diskfiledestinationoptions.diskfilename = exportpath + filename;                     exportoptions.exportdestinationtype = exportdestinationtype.diskfile;                     exportoptions.exportformattype = exportformattype.crystalreport;                     exportoptions.destinationoptions = diskfiledestinationoptions;                     break;                 }         }         try         {             //trying export input report document,              //and if success returns true             reportdocument.export();             return true;         }         catch (exception err)         {             return false;         }     } 

and report exported has no data in preview mode, not fields design mode.

someone, please ! new crystal reports.

if you're getting rpt file created, export code working fine.

for "empty" report, @ parameter code. anytime you're automating report , don't data, it's 99.9% of time related setting of parameters and/or record selection criteria (which many times uses parameters set).

look there.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -