2016-11-22 96 views
2

我一直在使用Crystal报告。我一直在开发Windows窗体中的库存系统。Crystal Report未显示来自Dataset的任何数据

因为我得从不同的表中的数据在Crystal Reports,所以我做了自定义的数据集和我需要的行填充它,如下所示:

代码:

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

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

+0

你好吗任何错误消息的形式?数据库和DataTable匹配的数据类型? – Prashanth

+0

dataType完全匹配。没有遗漏。 – Umar

回答

0

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

假设你已经在你的数据集充满了你的数据只是发送您的数据表到您的报告那样:

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

检查报告表的顺序在调试菜单,设置它这样,它会好的。 (或更改顺序,如果CR希望有一个另外的顺序)

+0

仍然没有工作。 – Umar

+0

我做了这件事 'rpt.Database.Tables [0] .SetDataSource((System.Data.DataTable)myDS.Company); rpt。Database.Tables [1] .SetDataSource((System.Data.DataTable)myDS.Invoice);' – Umar

+0

您是否在绑定之前检查了数据表中是否有一些行?在设置数据源之前和填充数据集之后关闭连接并尝试 – Furtiro

0

对于名称,地址和电话号码使用TextObjects(水晶报表文本字段),而不是数据表,并用它作为

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数据结果集

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

发票单独数据集单发票DataTable,并尝试下面的代码在哪里RSELECT是发票

012的结果集

以下代码是显示具有的CrystalReportViewer CRV

frmShowReport frm = new frmShowReport(); 
    frm.Show(); 
    reciept.SetDataSource(tblInvoice); 
    frm.crv.ReportSource = reciept; 
    frm.crv.Show(); 
+0

它引发indexOutOfBound异常: '((TextObject)rpt.ReportDefinition.ReportObjects [“txtCompanyName”]).Text = Company.Name; ' – Umar

+0

您是否在CrystalReports中插入了TextField而不是DataField – Prashanth

+0

是的,我在Crystal报表中添加了TextObject,将其名称设置为“txtCompanyName”,然后根据代码进行设置。 – Umar