我有一个简单的CrystalReports defigned。 屏幕截图:
我在Form Load
中填充DataSet protected override void OnLoad(EventArgs e)
{
CrystalReport2 report = new CrystalReport2();
DataSet data = GetData();
report.SummaryInfo.ReportTitle = "My Company Billing Report";
report.SetDataSource(data);
DateTime startTime = new DateTime(2015, 10, 1);
Debug.WriteLine("Start Time: " + startTime);
DateTime endTime = startTime.AddMonths(1);
Debug.WriteLine("End Time: " + endTime);
report.SetParameterValue("StartTime", startTime);
report.SetParameterValue("EndTime", endTime);
crystalReportViewer1.ReportSource = report;
//crystalReportViewer1.Refresh();
base.OnLoad(e);
}
private static DataSet GetData()
{
string connectString = ConfigurationManager.ConnectionStrings["TimeSheetContext"].ConnectionString;
SqlConnection connection = new SqlConnection {ConnectionString = connectString};
SqlCommand sqlCmd = new SqlCommand
{
CommandType = CommandType.Text,
Connection = connection,
CommandText = "SELECT * FROM tblTimeWorked ORDER BY Link2Customer, Link2Worker, DateWorked, Location"
};
BillingDataSet ds = new BillingDataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
int blah = da.Fill(dataSet: ds, srcTable: "tblTimeWorked");
Debug.WriteLine("# of TimeWorked Records: " + blah);
sqlCmd.CommandText = "SELECT * FROM tblActivity";
da = new SqlDataAdapter(sqlCmd);
blah = da.Fill(dataSet: ds, srcTable: "tblActivity");
Debug.WriteLine("# of Activity Records: " + blah);
sqlCmd.CommandText = "SELECT * FROM tblCustomer";
da = new SqlDataAdapter(sqlCmd);
blah = da.Fill(dataSet: ds, srcTable: "tblCustomer");
Debug.WriteLine("# of Customer Records: " + blah);
sqlCmd.CommandText = "SELECT * FROM tblWorker";
da = new SqlDataAdapter(sqlCmd);
blah = da.Fill(dataSet: ds, srcTable: "tblWorker");
Debug.WriteLine("# of Worker Records: " + blah);
return ds;
}
格式是我想要的,但似乎缺少一些条目。在我看来,只有第一人(工人)被选中,而其他人都没有。我是按客户分组,然后是CrystalReports中的员工。我没有对数据集进行任何过滤。我使用Sql Server Management Studio验证了记录。
记录选择是:
{tblTimeWorked.DateWorked} >= {?StartTime} and {tblTimeWorked.EndTime} < {?EndTime} and {tblTimeWorked.Link2Activity} = 2
为什么CrystalReports会在群组中跳过记录?
答案 0 :(得分:1)
我首先要尝试从Crystal Report中删除Group1和Group2,然后运行报告,以确认水晶报告确实包含了您期望的所有详细信息行。此外(也许更重要的是),在报告中包含多个数据集似乎很奇怪。只需修改您的第一个CommandText,即可包含拉动您需要的其他链接字段所需的连接(例如,客户名称,员工姓名)。这将简化事情。