I am creating a C# windows form application using Visual Studio 2010.
The end goal of this application is to enable easy modification of a database table hosted in windows server 2005.
The table has four fields: “StoreNumber”, “PlannedSales”, “Year”, and “WeekNumber”.
The query I would like to use to fill the data grid looks like this:
SELECT StoreNumber, PlannedSales
FROM PlannedSalesTable
WHERE Year = [YearUpDownPicker].value and Weeknumber = [WeekUpDownPicker].value
(I would like the DataGrid to show data a week at time.)
The updownPickers are what I would like to use to make a year and week selection. Unfortunately everything available in the tool strip, created by adding a filtering query to the table adaptor, seems to be inadaquate or too complicated for the purporses of simply limiting the data the user would see.
(Why use a Drop Down or TextBox to pick a week to view when a NumericUpDown does all the validation for me…)
Is it possible to use a filtering expression on the datagrid view based on the values of a control?
How would I do it, and what would be the best way to then update the database using those same controls as inputs for YEAR and MONTH.
Thanks for the Help.
Figured it out!
I used:
BindingSource.Filter = string.Format(“WeekNumber='{0}’ and Year='{1}'”, week, year);
TableAdapter.Fill(DataSet);
(Variables week and year were defined using the number pickers beforehand.)
The statement above was called during an on-click event, and it automatically refreshed the table. Make sure the table adaptor’s ‘clear before fill’ property is set to ‘true’
Still need to figure out how to update it this way. But for now it is displaying.