'Crystal Report Not showing any data from Dataset

I have been using Crystal reports from a long time. I had been developing an inventory system in windows forms.

Since I have to get data from different tables in Crystal reports, so i have made custom data set filled it with my required rows as follows:

Code:

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;

Image of CR designed report:

enter image description here

Image of Custom Dataset:

enter image description here

Dataset filled image

enter image description here

Empty report

enter image description here

Question: Since everything is perfect. Why my data does not show on report?



Solution 1:[1]

I had the same problem with data not displaying at all.

Assuming you already have your dataSet filled with your data just sent your datatable to your report like that :

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

Check the order of your report Tables in the debug menu, set it like this and it will be ok. ( or change the order if CR wants an other order )

Solution 2:[2]

For Name, Address, Phone No Use TextObjects(Crystal Reports Text Field) instead of DataTable and use it as

    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"];

Considering you have fetched the data from DB rSelect is the resultSet

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

For Invoice alone DataSet With single INVOICE DataTable and try the Below Code Where rSelect is the ResultSet of Invoice

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

The below code is to display a form with CrystalReportViewer crv

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Furtiro
Solution 2 Prashanth