[英]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;
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.