繁体   English   中英

Crystal Report 未显示来自 Dataset 的任何数据

[英]Crystal Report Not showing any data from Dataset

我一直在使用水晶报表很长一段时间。 我一直在开发 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设计报告图片:

在此处输入图片说明

自定义数据集的图像:

在此处输入图片说明

数据集填充图像

在此处输入图片说明

空报告

在此处输入图片说明

问:既然一切都是完美的。 为什么我的数据没有显示在报告中?

我有同样的问题,数据根本不显示。

假设你已经有你的 dataSet 填充了你的数据,只是将你的数据表发送到你的报告中:

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

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

对于姓名、地址、电话,不使用 TextObjects(Crystal Reports Text Field)而不是 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();

对于单独的发票数据集使用单个发票数据表并尝试以下代码其中 rSelect 是发票的结果集

    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();

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM