DEV Community

Seenu Seenu
Seenu Seenu

Posted on

Building a Dynamic Sales Report: Implementing Date Range Filtering in C# Windows Forms

From Date: 01-12-2025 (December 1st)

To Date: 09-01-2026 (January 9th)

As you can see, the DataGridView now populates with a much larger list of bills, and the Total Amount automatically updates to reflect the cumulative sales (17,130.00).

From Date: 01-01-2026

To Date: 09-01-2026

By selecting these dates and clicking the "TOTAL" button, the application filters the records and calculates the total sales for just those 9 days (Total: 420.00).

(Backend)

using (SqlCommand cmd = new SqlCommand(query, connection))
{
// Binding the DateTimePicker values to SQL parameters
cmd.Parameters.AddWithValue("@StartDate", dateTimePickerFrom.Value.ToString("yyyy-MM-dd"));
cmd.Parameters.AddWithValue("@EndDate", dateTimePickerTo.Value.ToString("yyyy-MM-dd"));

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);

// Binding data to the Grid
dataGridView1.DataSource = dataTable;
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)