2011-01-10 85 views

回答

1

您可以手動參數傳遞給水晶報表後無法正常工作的功能。通過這種方式,您可以創建自己的參數窗體,並且可以處理用戶輸入以將其發送到報表。這裏是一個片段來向您展示如何做到這一點:

ReportDocument doc = new ReportDocument(); 
doc.Load(Path.Combine(basePath, report.Name + ".rpt")); 
doc.SetDataSource(dataTable); 

// set parameters defined in Paramenter fields inside the rpt 
var value = new ParameterDiscreteValue(); 
value.Value = valueYouWantToPass; 
doc.ParameterFields["nameOfTheParamenterField"].CurrentValues.Add(value); 
1

嘗試:

 Imports CrystalDecisions 
     Imports CrystalDecisions.CrystalReports 
     Imports CrystalDecisions.CrystalReports.Engine 
     Imports CrystalDecisions.Shared 

     Dim RptDoc As New ReportDocument() 
     Dim CrTables As Tables 
     Dim CrTable As Table 
     Dim crtableLogoninfo As New TableLogOnInfo 
     RptDoc.Load(Server.MapPath(ReportFullFilename)) 

        With crConnectionInfo 
         .ServerName = "myServer" 
         .DatabaseName = "myDatabase" 
         .UserID = "myUserID" 
         .Password = "myPassword" 
        End WITH 

     CrTables = RptDoc.Database.Tables 

     For Each CrTable In CrTables 
      crtableLogoninfo = CrTable.LogOnInfo 
      crtableLogoninfo.ConnectionInfo = crConnectionInfo 
      CrTable.ApplyLogOnInfo(crtableLogoninfo) 
     Next 

     RptDoc.SetDatabaseLogon(crConnectionInfo.UserID, crConnectionInfo.Password, crConnectionInfo.ServerName, crConnectionInfo.ServerName) 


     RptDoc.SetParameterValue("FromDate", FromDatePicker.SelectedDate) 
     RptDoc.SetParameterValue("ThruDate", ToDatePicker.SelectedDate) 

     Dim stream As New BinaryReader(RptDoc.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat)) 
     Response.ClearContent() 
     Response.ClearHeaders() 
     Response.ContentType = "application/pdf" 
     Response.AddHeader("content-disposition", Convert.ToString("attachment; filename=") & downloadAsFilename) 
     Response.AddHeader("content-length", stream.BaseStream.Length.ToString()) 
     Response.BinaryWrite(stream.ReadBytes(Convert.ToInt32(stream.BaseStream.Length))) 
     Response.Flush() 
     Response.Close()