2012-03-29 92 views
0

我在C sharp中使用SAP CR for VS 2010。我有五個表,我將它們與以下查詢鏈接:SAP Crystal Reports for VS 2010.在運行時更改查詢

query =「SELECT Items.AccessionNo,Items.Name,Items.LocalName,Items.Usage,Items.Province,Items.District,Items.VillTown, Items.EthnicCommunity,Arts.Name,Items.PurchasedDonated,Items.PurchasedFrom,Items.YearOfCollection,Items.Material,Items.Height,Items.Width,Items.Length,Items.Circumference,Items.Diameter,Items.Color,Items。年齡,Items.Weight,Items.PurchasedValue,Items.Rare,Items.LivingDyingTrad,Items.ManufacturingProcess,Items.PlaceOfManufacturing,Items.ConditionReport,Items.Recommandations,Items.DateOfAddition,Items.Placement,Donators.Name,Collectors.Name, Placement.Name FROM Items INNER JOIN Arts ON Items.ArtId = Arts.ArtId INNER JOIN Donators ON Items.DonatorId = Donators.id INNER JOIN Collectors ON Items.CollectorId = Collectors.id INNER JOIN Placement ON Items.PlacementId = Pla cement.id WHERE Items.id =「+ itemid;

問題是報告在設計時仍然使用已嵌入的查詢顯示多個結果。

我使用下面的代碼通過上面的查詢

  SqlCommand cmd = new SqlCommand(query, dbconn.conn); 
      if (dbconn.conn.State == ConnectionState.Closed) 
      { 
       dbconn.conn.Open(); 
      } 

      SqlDataAdapter Datadpt = new SqlDataAdapter(cmd); 

      DataSet dtset = new DataSet("items"); 
      Datadpt.Fill(dtset); 
      //rep is the Report document object already defined 
      rep.Load(@"..\..\Reports\CRItem.rpt"); 
      rep.SetDataSource(dtset); 
      CRViewer.ReportSource = rep; 
      if (dbconn.conn.State == ConnectionState.Open) 
      { 
       dbconn.conn.Close(); 
      } 
      this.CRViewer.RefreshReport(); 

有什麼建議?

+0

結果是否都具有相同的'Items.id'值? – 2012-03-29 07:46:33

+0

否。報告顯示數據庫中的所有行。它不根據查詢過濾數據。 – user1300054 2012-03-29 08:23:15

+0

做'this.CRViewer.Refresh();'做任何不同的'this.CRViewer.RefreshReport();'? – 2012-03-29 09:27:41

回答

0

whoooosss .....我明白了。 crystalreportviewer選擇公式與報告文檔記錄選擇公式是分開的。記錄選擇您在水晶報表中創建的公式存儲在ReportDoc.RecordSelectionFormula屬性中。將ReportDoc加載到ReportViewer時,它不會採用.RecordSelectionFormula的值ReportViewer.SelectionFormula屬性。所以我做了什麼....

我的對象是:

ReportDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument 
ReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer 
FlexReportDoc.SetParameterValue("Reference", gsReference) 

通過必要的參數後,如果您有任何...

ReportViewer.ReportSource = FlexReportDoc 
ReportViewer.SelectionFormula = FlexReportDoc.RecordSelectionFormula 

您需要分配的FlexReportDoc.RecordSelectionFormula值物業到ReportViewer.SelectionFormula

相關問題