Crystal Report未显示Dataset的任何数据

时间:2016-11-22 06:54:28

标签: c# winforms crystal-reports

我一直在使用Crystal报告。我一直在开发Windows窗体的库存系统。

由于我必须从Crystal报表中的不同表中获取数据,因此我使用我所需的行填充了自定义数据集,如下所示:

代码:

cmd = new SqlCommand();
SqlDataAdapter myDA = new SqlDataAdapter();
CustomDataSet myDS = new CustomDataSet();

con = new SqlConnection(cs.DBConn);
cmd.Connection = con;

//receipt code goes here
                string query = "select Customer.CustomerName as Name,Customer.Address as Address,Customer.ContactNo as ContactNo, Product.ProductName as ItemName, ProductSold.Quantity as Quantity, Invoice_Info.InvoiceNo as InvoiceNumber, ProductSold.Price as PriceOfItem, ProductSold.Tax as TaxOnItem, ProductSold.Discount as DiscountOnItem, Invoice_Info.TotalPayment as PaidAmount, Invoice_Info.SoldBy as Salesman, Invoice_Info.CashedBy as Cashier, Invoice_Info.DiscountAmount as DiscountOnInvoice, Invoice_Info.PaymentType as PaymentType from Invoice_Info,Product,ProductSold,Customer where Invoice_Info.CustomerID=Customer.CustomerId and Invoice_Info.InvoiceNo=ProductSold.InvoiceNo and ProductSold.ProductID=Product.ProductId and Invoice_Info.InvoiceNo=" + txtInvoiceNo.Text;
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
myDA.SelectCommand = cmd;
myDA.Fill(myDS.Invoice);

//if customer is walking customer show change else show credit of regular customer
if (txtCustomerName.Text == Constants.WalkingCustomer)
{
for (int i = 0; i < myDS.Invoice.Count; i++)
{
myDS.Invoice[i].Balance = double.Parse(txtTotal.Text) - double.Parse(txtTotalPayment.Text);
}
}

//filling company informtation
myDS.Company.AddCompanyRow(Company.Name, Company.Address, Company.Phone);
rptReceipt rpt = new rptReceipt();
rpt.SetDataSource(myDS);
frmInvoiceReport frm = new frmInvoiceReport();
frm.crystalReportViewer1.ReportSource = rpt;
frm.crystalReportViewer1.RefreshReport();
frm.Visible = true;

CR设计报告的图片:

enter image description here

自定义数据集的图片:

enter image description here

数据集填充图片

enter image description here

空报告

enter image description here

问题: 因为一切都很完美。为什么我的数据不会在报告中显示?

2 个答案:

答案 0 :(得分:0)

我的数据根本没有显示也有同样的问题。

假设您已经在数据集中填充了数据,只需将数据表发送到您的报告中:

        rptH.Database.Tables[0].SetDataSource(myDataTableCompany);
        rptH.Database.Tables[1].SetDataSource(myInvoiceDataTable);

检查调试菜单中报告表的顺序,将其设置为这样就可以了。 (如果CR需要其他订单,则更改订单)

答案 1 :(得分:0)

对于名称,地址,电话不使用TextObjects(Crystal Reports文本字段)而不是DataTable并将其用作

    rptReciept reciept = new rptReciept();

    TextObject tName = (TextObject)reciept.ReportDefinition.ReportObjects["txtName"];
    TextObject tAddress = (TextObject)reciept.ReportDefinition.ReportObjects["txtAddress"];
    TextObject tPhone = (TextObject)reciept.ReportDefinition.ReportObjects["txtPhoenNo"];

考虑到你从DB获取数据rSelect是resultSet

    tName.Text = rSelect.Table["c_name"].ToString();
    tAddress.Text = rSelect.Table["c_address"].ToString();
    tPhone.Text = rSelect.Table["c_phone"].ToString();

对于单独的Invoice DataSet,使用单个INVOICE DataTable并尝试下面的代码,其中rSelect是Invoice的ResultSet

    CustomDataSet dsInvoice = new CustomDataSet();
    DataTable tblInvoice = rSelect.ResultSet;
    tblInvoice.TableName = "tblInvoice"; // The TableName which you used while creating the DataTable in DataSet.
    dsInvoice.Merge(tblInvoice);

以下代码用于显示CrystalReportViewer crv

的表单
    frmShowReport frm = new frmShowReport();
    frm.Show();
    reciept.SetDataSource(tblInvoice);
    frm.crv.ReportSource = reciept;
    frm.crv.Show();