0

I am working on a Windows Forms application using C#, Entity Framework and a SQL Server database.

I have a stored procedure to select last order id at today:

ALTER PROCEDURE [dbo].[GET_ORDER_DETAILS_FOR_PRINT]
    @ID_ORDER INT,
    @SpecificDate DATE
AS
    SELECT 
        Orders.[ID_Order] AS ' رقم الفاتورة',
        Orders.[OrderDate] AS 'تاريخ الفاتورة',
        Orders.[OrderTime] AS 'وقت الفاتورة',
        Orders.[SALESMAN] AS 'اسم البائع',
        Orders.[CustmerName] AS 'اسم العميل ',
        Orders.Product_name AS 'اسم المنتج',
        CONVERT(float, Orders.Product_SellingPrice) AS 'ثمن الوحدة ',
        CONVERT(float, Orders.[Product_Qte]) AS ' الكمية',
        CONVERT(float, Orders.[Qte_price]) AS ' ثمن الكمية',
        CONVERT(float, Orders.Product_Discount) AS 'الخصم',
        CONVERT(float, Product_TotalPrice) AS ' قيمة المنتج',
        CONVERT(float, TotalOrder) AS 'إجمالي المشتروات',
        CONVERT(float, Orders.CustomerDepit) AS 'الرصيد السابق',
        CONVERT(float, Order_Price_without_discount) AS ' الاجمالي',
        CONVERT(float, Cash) AS 'نقدا',
        CONVERT(float, [REMAINDER]) AS 'الباقي'
    FROM 
        [dbo].Orders
    WHERE 
        Orders.ID_Order = @ID_ORDER
        AND Orders.[OrderDate] = @SpecificDate

As you can see the stored procedure takes two values so I am passing those two values in this code below when I click a print button

private void BTN_PRINT_Click(object sender, EventArgs e)
{
        var SpecificDate = dateTimePicker1.Value.Date;
        var records = db.Orders.Where(p => p.OrderDate == SpecificDate);
        var ID_ORDER = records.Max(a => a.ID_Order);

        Reportss.OrderDetailsReport MyReport = new Reportss.OrderDetailsReport();
        // MAKING AN OBJECT FROM THE FORM THAT REPRESENT THE REPORT 
        Reportss.Form1 frm = new Reportss.Form1();
        MyReport.SetDataSource(db.GET_ORDER_DETAILS_FOR_PRINT(ID_ORDER, SpecificDate));
        frm.crystalReportViewer1.ReportSource = MyReport;
        frm.Show();    
    }

The problem is when I hit print button, I get an exception:

System.NotSupportedException: 'DataSet does not support System.Nullable<>.'

When I debugged my code, I found that

SpecificDate = {8/21/2020 12:00:00 AM}

and

ID_ORDER=58  

comparing with database:

OrderDate = 2020-08-21 00:00:00.000 and ID_ORDER = 58
ndogac
  • 1,185
  • 6
  • 15
bahi
  • 1
  • 8

1 Answers1

0

If you're using (ReportDocument) then you need to correct the parameters:

ReportDocument

To create a DataSet:

DataSet

Toni
  • 1,555
  • 4
  • 15
  • 23