Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I need help in connecting my Stored Procedure for Total Price of Sales per month. I need to be able to Search for the month or date pick then from that selection, have it view on a DataGrid. My problem right now is that I'm not quite sure on how to get and set the variables in my query. Also pretty much view the total price of a selected month.

What I have tried:

Query for View Total Price per Month
SQL
SELECT YEAR(RentDate)[Year], MONTH(RentDate)[Month], DATENAME(MONTH,RentDate)[MONTH Name], SUM(TotalPrice) [Total Rental Price]
	FROM TruckRental
	WHERE MONTH(RentDate) = MONTH(@rentDate)
	GROUP BY YEAR(RentDate),MONTH(RentDate),DATENAME(MONTH,RentDate)
	ORDER BY 1,2

Parameter is also
SQL
@rentDate date

My Get Set Code:
C#
public class TruckRentalData
    {
        [Key]
        public DateTime RentDate { get; set; }
        public decimal TotalPrice { get; set; }

    }


My DataService Code:

C#
static public List<TruckRentalData> searchTruckByMonth(DateTime Month)
        {
            using (var ctx = new DDQ4_Grace_DAD_PartBContext())
            {
                return ctx.TruckRentalData.FromSql("MonthlyRental @p0",Month).ToList();
            }
        }


My Button Code:

C#
private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            DateTime month = getDate.DisplayDate;
            TruckDataGrid2.ItemsSource = DataService.searchTruckByMonth(month);
        }
Posted
Comments
Richard Deeming 27-Nov-18 12:51pm    
"Query for View Total Price per Month"

Do you actually mean a view[^]? If so, that won't work - views can't have parameters.

From the way you're executing it, I suspect you meant a stored procedure[^], which would almost work, except the columns you're returning don't match the properties in your class.
ZurdoDev 29-Nov-18 15:37pm    
I have no idea what you are asking us.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900