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
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
@rentDate date
My Get Set Code:
public class TruckRentalData
{
[Key]
public DateTime RentDate { get; set; }
public decimal TotalPrice { get; set; }
}
My DataService Code:
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:
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
DateTime month = getDate.DisplayDate;
TruckDataGrid2.ItemsSource = DataService.searchTruckByMonth(month);
}