none
Getting values from diiferent tables in a database and ahow in a single tablix of ReportViewer (.rdlc). RRS feed

  • Question

  • Hello,

    I am working on a billing software. I would like to generate an Invoice containing values from 3 different tables of a database.

    XAML

            <WindowsFormsHost Height="504">
                <rv:ReportViewer x:Name="_reportViewer"/>
            </WindowsFormsHost>

    Code Behind

            private DataTable GetEmployeeData()
            {
                try
                {
                    // Open Sql Connection  
                    con.Open();
                    DataTable dt = new DataTable();
                    // Create a Command  
                    SqlCeCommand com5 = new SqlCeCommand("SELECT MAX(OrderID) AS Expr1 FROM Order_Details", con);
                    maxOrderID = (int)com5.ExecuteScalar();
                    SqlCeCommand com = new SqlCeCommand("SELECT Products_Master.ProductName, Order_Products.Quantity, Order_Details.TotalTax, Order_Products.Cost, Order_Details.Discount, Order_Details.TotalPrice FROM Order_Products INNER JOIN Order_Details ON Order_Details.OrderID = Order_Products.OrderID INNER JOIN Products_Master ON Products_Master.ProductCode = Order_Products.ProductCode WHERE (Order_Details.OrderID = '" + maxOrderID + "')", con);
                    SqlCeDataReader dr = com.ExecuteReader();



                    // Create instance of Northwind DataSetXSD  
                    //BillingDatabaseDataSet.Order_ProductsDataTable productsDT = new BillingDatabaseDataSet.Order_ProductsDataTable();

                    // Set a Data Commands  
                    SqlCeDataAdapter SqlDa = new SqlCeDataAdapter(com);

                    SqlDa.Fill(dt); // Fill Data in NorthwindDataSet Object.  

                    return dt;

                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            private void ReportViewer_Load(object sender, EventArgs e)
            {
                if (!_isReportViewerLoaded)
                {

                    Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
                    BillingDatabaseDataSet dataset = new BillingDatabaseDataSet();

                    dataset.BeginInit();

                    reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file
                    reportDataSource1.Value = dataset.Order_Products;
                    this._reportViewer.LocalReport.DataSources.Add(reportDataSource1);
                    this._reportViewer.LocalReport.ReportEmbeddedResource = "Billing.Report1.rdlc";

                    dataset.EndInit();

                    //fill data into Order_ProductsDataSet
                    BillingDatabaseDataSetTableAdapters.Order_ProductsTableAdapter salesOrderDetailTableAdapter = new BillingDatabaseDataSetTableAdapters.Order_ProductsTableAdapter();
                    salesOrderDetailTableAdapter.ClearBeforeFill = true;
                    salesOrderDetailTableAdapter.Fill(dataset.Order_Products);

                    _reportViewer.RefreshReport();

                    _isReportViewerLoaded = true;
                }
            }

    But i am not able to add these custom values to my report viewer.

    I am using Visual Studio 2012, Sql Server Ce, WPF, C# for coding.

    Thursday, November 7, 2013 11:22 AM