简体   繁体   English

如何使用mysql命令条件语句在Crystal报表中显示数据?

[英]how to display data in crystal reports using mysql command conditional statement?

I am having a problem displaying conditional statement on my crystal reports. 我在水晶报表上显示条件语句时遇到问题。 I want to display those customers who has a "Paid" status but it seems that my code didn't work because it still displays all of my data from database. 我想显示那些具有“已付费”状态的客户,但是我的代码似乎无法正常工作,因为它仍显示数据库中的所有数据。

        MySqlConnection conn;
        MySqlCommand cmd;
        MySqlDataAdapter adap;

        conn = new MySqlConnection("Server=localhost; Database=order&billing; " +
            "User ID=root; Password=; charset=utf8;"); conn.Open();
        cmd = conn.CreateCommand();
        cmd.CommandText = "select `order`.or_no,`order`.balance,`order`.totalprice, `order`.paid,customer.fname,customer.lname,customer.addr, customer.status, caterselected.catsel from `order` left join customer on `order`.custid=customer.custid left join caterselected on caterselected.nserveid=`order`.nserveid where `customer`.status='Paid'";

        adap = new MySqlDataAdapter();
        adap.SelectCommand = cmd;
        DataSet1 custDB = new DataSet1();
        custDB.Clear();
        adap.Fill(custDB, "cust");



        CrystalReport1 myReport = new CrystalReport1();
        myReport.SetDataSource(custDB); 
        crystalReportViewer1.ReportSource = myReport; 

这是我的数据集1 And this is the output of my crystal reports 这是我的水晶报告的输出 水晶报告

You are using somewhat strange filtering logic in your SQL query. 您在SQL查询中使用了一些奇怪的过滤逻辑。 This is the query. 这是查询。

select `order`.or_no,
       `order`.balance,
       `order`.totalprice,
       `order`.paid,
       customer.fname,
       customer.lname,
       customer.addr,
       customer.status,
       caterselected.catsel
  from `order` 
  left join customer on `order`.custid=customer.custid
  left join caterselected on caterselected.nserveid=`order`.nserveid
 where `customer`.status='Paid'

This where clause pulls selects customer rows with a paid status, and incidentally converts the left join customer clause to an inner join customer clause by putting a filter condition on the left table. where子句拉取选择具有付款状态的客户行,并通过在左表上放置一个过滤条件,顺便将left join customer子句转换为inner join customer子句。

But there's nothing in your tables (that I can see) requiring a customer with Paid status to have only orders with Paid status. 但是您的表(我可以看到)中没有任何内容要求具有“已付款”状态的客户只能拥有“已付款”状态的订单。 You haven't explained your business logic sufficiently for us to understand what it means for a Paid customer to have an Unpaid order. 您尚未充分说明您的业务逻辑,以使我们了解付费客户拥有未付款订单的含义。

What happens if you use this WHERE clause instead? 如果改用此WHERE子句会怎样?

 where `order`.status='Paid'
myReport.SetDataSource(custDB.Tables(0)); 

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

相关问题 如何在Crystal报表中显示数据网格 - How to display grid of data in crystal reports C#Windows Crystal Reports,如何以编程方式在Crystal报表中显示数据表 - C# windows Crystal Reports, How to display a data table in crystal reports programmatically 如何在 Crystal Reports 中将列数据显示为行 header - How to display column data as row header in Crystal Reports 在不使用ASP Crystal Reports Viewer的情况下以HTML格式显示Crystal Reports - Display Crystal Reports in HTML without using ASP Crystal Reports Viewer 水晶报告 - 公式字段条件语句对什么记录求和 - crystal reports - formula field conditional statement on what records to sum 如何在Crystal Reports Viewer上显示来自本地数据源(sdf)的报告? - How do I display Reports from a Local Data Source (sdf) on a Crystal Reports Viewer? 使用URL在Crystal报表中显示图像 - Display Image in Crystal reports Using URL 如何使用Winforms在Crystal Reports中从GridView打印数据? - How to print data from a GridView in Crystal Reports using Winforms? 使用C#在Crystal Reports中使用外键显示来自两个表的数据 - Display data from two tables with foreign key in Crystal Reports using C# 如何在Crystal Reports中检查数据源是否为空 - How to check if data source is empty in Crystal Reports
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM