简体   繁体   English

我的SQL查询在Crystal报表上重复

[英]My sql query duplicates on crystal reports

Im having trouble why my query(on sql server) is duplicating on crystal reports. 我有麻烦为什么我的查询(在SQL Server上)在Crystal报表上重复。 Providing the screenshots of my work! 提供我的作品的屏幕截图! This is my code. 这是我的代码。

            myCommand = new SqlCommand("SELECT Issuance.i_ID, ProductSold.ps_pID, ProductSold.ps_Name, ProductSold.ps_Qty,Issuance.i_Issued,Issuance.i_Received,Issuance.i_Received,Issuance.i_Approved,Issuance.i_Purposed,ProductSold.ps_Amount,ProductSold.ps_Serial,Issuance.i_EntryDate FROM Issuance LEFT JOIN ProductSold ON Issuance.i_ID = ProductSold.ps_IssID WHERE Issuance.i_ID='" + txtIssuanceID.Text + "'", myConnection);
            myCommand.Connection.Open();
            myConnection.Close();
            SqlDataAdapter sda = new SqlDataAdapter(myCommand);
            DataSet ds = new DataSet();
            sda.Fill(ds, "Issuance");
            sda.Fill(ds, "ProductSold");
            rptMCT report = new rptMCT();
            report.SetDataSource(ds);
            report.VerifyDatabase();
            crystalReportViewer1.ReportSource = report;
            crystalReportViewer1.RefreshReport();

img-sql query , img-sql查询

img-output in crystal reports , Thanks! img-输出水晶报表 ,谢谢!

Try checking your query. 尝试检查您的查询。 almost all of the time, Joins duplicate the results of the crystal reports, because it would just replicate the output of your SQL statement. 几乎所有时候,Joins都会复制水晶报表的结果,因为它只会复制SQL语句的输出。 You have to verify first in your query explorer of your DBMS if your query produces your desired output. 如果查询产生所需的输出,则必须首先在DBMS的查询浏览器中进行验证。

For one, your image shows the join: 首先,您的图像显示了联接:

from ProductSold left join Issuance

But your code sample shows the opposite. 但是您的代码示例却显示了相反的情况。 The same problem exists in the where clause - where you compare your text value (sql injection vulnerability) to the preserved table in your join. where子句中存在相同的问题-您将文本值(sql注入漏洞)与联接中保留的表进行比较。

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

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