简体   繁体   English

当我对数据集使用查询时,Crystal报表会重复这些项目

[英]Crystal reports repeating the items when i am using the query with dataset

I am new to crystal report. 我是水晶报告的新手。 At the time of binding the data from dataset to the crystal report showing twice or thrice. 在将数据集的数据绑定到晶体报告时,显示两次或三次。

I am using SQL 2005 and VS 2008. 我正在使用SQL 2005和VS 2008。

i checked in SQL and dataset also at the time of debugging but in dataset only i am having 5 records but in my crystal its showing 10 records. 我也在调试时检查了SQL和数据集,但仅在数据集中我有5条记录,但在我的水晶中显示了10条记录。

Below is my Code: 以下是我的代码:

ReportDocument doc = new ReportDocument();

sda = new SqlDataAdapter(" SELECT ac_mstr.AC_DESC, TRAN_HDR.DOC_DT, TRAN_DTLS.GL_CODE,    DBCR, AMT FROM dbo.TRAN_DTLS TRAN_DTLS INNER JOIN dbo.AC_MSTR ac_mstr ON (TRAN_DTLS.SUB_CODE=ac_mstr.SUB_CODE) AND (TRAN_DTLS.GL_CODE=ac_mstr.GL_CODE) INNER JOIN dbo.TRAN_HDR TRAN_HDR ON (TRAN_DTLS.TC=TRAN_HDR.TC) AND (TRAN_DTLS.DOC_NO=TRAN_HDR.DOC_NO) where tran_hdr.tc='CAS' and tran_hdr.doc_dt between '2012/01/01' and '2012/12/30'   ORDER BY TRAN_DTLS.GL_CODE", con);

        sda.Fill(ds);      
       doc.Load(Server.MapPath("~/Reports/Acc_sum.rpt"));

      doc.SetDataSource(ds.Tables[0]);
      CrystalReportViewer1.ReportSource = doc;

Can any one help Me? 谁能帮我?

the mistake came from your query: 错误来自您的查询:

    SELECT ac_mstr.AC_DESC, TRAN_HDR.DOC_DT, TRAN_DTLS.GL_CODE,    DBCR, AMT 
FROM dbo.TRAN_DTLS TRAN_DTLS INNER JOIN dbo.AC_MSTR ac_mstr
 ON (TRAN_DTLS.SUB_CODE=ac_mstr.SUB_CODE) AND (TRAN_DTLS.GL_CODE=ac_mstr.GL_CODE) 
INNER JOIN dbo.TRAN_HDR TRAN_HDR ON (TRAN_DTLS.TC=TRAN_HDR.TC) AND (TRAN_DTLS.DOC_NO=TRAN_HDR.DOC_NO) where tran_hdr.tc='CAS' and tran_hdr.doc_dt between '2012/01/01' and '2012/12/30'   ORDER BY TRAN_DTLS.GL_CODE

which make your data appear twice so change your query . 这会使您的数据出现两次,因此请更改查询。

Crystal Reports can do unexpected thing with data. Crystal Reports可以对数据进行意外处理。 A great place to start debugging (besides opening the crystal report in an editor and clicking around) is to use SQL Server Profiler. 开始调试(在编辑器中打开Crystal报表并单击四周)的好地方是使用SQL Server Profiler。 A more detailed tutorial can be found at http://www.databasejournal.com/features/mssql/article.php/3750161/Introduction-to-SQL-2005-Profiler-Part-1.htm . 可以在http://www.databasejournal.com/features/mssql/article.php/3750161/Introduction-to-SQL-2005-Profiler-Part-1.htm上找到更详细的教程。

It is important to note that while SQL Server 2005 Express can be used with SQL Server Pro filer, it does not come bundled with the program. 重要的是要注意,尽管SQL Server 2005 Express可以与SQL Server Pro文件管理器一起使用,但它并不与程序捆绑在一起。

I have attached a basic set of directions for your convenience: 为了方便起见,我附上了一套基本的指导说明:

- --

  1. Open SQL Server Profiler: 打开SQL Server Profiler:
    • From the start menu: \\All Programs\\Microsoft SQL Server 2005\\Performance Tools\\SQL Server Profiler. 从开始菜单:\\ All Programs \\ Microsoft SQL Server 2005 \\ Performance Tools \\ SQL Server Profiler。
    • From SQL Server Management Studio: Tools\\SQL Server Profiler 从SQL Server Management Studio:Tools \\ SQL Server Profiler
  2. Press the new trace button which is the left most button on the tool bar. 按下新的跟踪按钮,它是工具栏上最左侧的按钮。

  3. Connect to the SQL server which is hosting your data. 连接到托管数据的SQL Server。

  4. On the Trace Properties screen press the run button. 在“跟踪属性”屏幕上,按运行按钮。
    (Their are a number of usuful features on the Events Selection tab, but for your purposes the default settings should be fine.) (它们在“事件选择”选项卡上有许多有用的功能,但是出于您的目的,默认设置应该可以。)

  5. Run your program. 运行程序。

Using the default settings you should be able to see when ever anything accesses your database, and what queries they use to do the accessing. 使用默认设置,您应该能够看到什么时候访问数据库,以及它们使用什么查询进行访问。 This way you can see if your query is correct or if there are other issues. 这样,您可以查看查询是否正确或是否存在其他问题。

I have also seen (rarely) in the past crystal reports performing a local join on the data which resulted in duplicates. 我也曾经(很少)看到Crystal报表对数据执行本地联接,从而导致重复。 When this has happened to me I have had to remove large chunks of the report, or even create a new report and test it at each step, to determine where the issue is. 当发生这种情况时,我不得不删除大量报告,甚至创建一个新报告并在每个步骤中对其进行测试,以确定问题出在哪里。

Please let me know if you require additional assistance. 如果您需要其他帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM