gpt4 book ai didi

c# - 在数据集中使用多个数据表

转载 作者:行者123 更新时间:2023-11-29 19:42:54 26 4
gpt4 key购买 nike

我必须创建一个 Crystal 报表,其数据将从数据集中填充。数据集有三个数据表。即:

CustDetais
BookingDetails
FoodNExtra

当我通过 Crystal Report Wizard 设置 Crystal Report 时,我得到了一个新屏幕,上面显示 enter image description here不知道在这里做什么,所以我只是点击下一步。这是我的 Crystal 报表查看器代码:

private void CRKOTQoute_Load(object sender, EventArgs e)
{
try
{
MySqlCommand cmd = new MySqlCommand("select CustName,Phone,Address,Email from tblCustDetails where custid=@custid", con.con);
cmd.Parameters.AddWithValue("@custid", BLDashboard.custid);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet1 ds = new DataSet1();
adapter.Fill(ds, "CustDetais");
if (ds.Tables["CustDetais"].Rows.Count == 0)
{
MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
MySqlCommand cmd1 = new MySqlCommand("select BookingID,BookingDate,Event,EventDate,EventTime,Pax,Service,ServiceTime from tblBookingDetails where BookingID=@Bookid", con.con);
cmd.Parameters.AddWithValue("@bookid", BLDashboard.bookingID);
MySqlDataAdapter adapter1 = new MySqlDataAdapter(cmd1);
DataSet1 ds1 = new DataSet1();
adapter.Fill(ds1, "BookingDetails");
if (ds1.Tables["BookingDetails"].Rows.Count == 0)
{
MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
MySqlCommand cmd2 = new MySqlCommand("select FoodMenu,ExtraItem from tblItem where BookingID=@Bookid1", con.con);
cmd.Parameters.AddWithValue("@bookid1", BLDashboard.bookingID);
MySqlDataAdapter adapter2 = new MySqlDataAdapter(cmd2);
DataSet1 ds2 = new DataSet1();
adapter.Fill(ds2, "BookingDetails");
if (ds2.Tables["FoodNExtra"].Rows.Count == 0)
{
MessageBox.Show("No Data Found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
RPTKOTQoute printKOTqoute = new RPTKOTQoute();
//RPTKitchenQoute printKOTqoute = new RPTKitchenQoute();
//RPTKOTTest printKOTqoute = new RPTKOTTest();
printKOTqoute.SetDataSource(ds);
printKOTqoute.SetDataSource(ds1);
printKOTqoute.SetDataSource(ds2);
crystalReportViewer1.ReportSource = printKOTqoute;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
printKOTqoute.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
printKOTqoute.PrintOptions.PrinterName = "EPSON TM-U220 Receipt";
printKOTqoute.PrintToPrinter(1, false, 0, 0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

我使用了与提到的相同的方式here .

当我运行 Crystal 报表时,没有错误,但没有显示数据。我尝试只使用一个数据表,效果很好。我也使用 MySQL 作为数据库。

最佳答案

尝试将三个数据集合并为一个,然后再将它们分配给报表数据源:

ds.Merge(ds1)
ds.Merge(ds2)

这样,ds 应包含 dsds1ds2 中的所有数据(所有表)。然后,仅指定 ds 作为报表的数据源。

关于c# - 在数据集中使用多个数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41240127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com