I have the following sp:
CREATE PROCEDURE SheriffSale.usp_combinedsearch
@SaleId nvarchar(25) = NULL,
@City nvarchar(50) = NULL,
@ZipCode nvarchar(10) = NULL,
@County nvarchar(25) = NULL,
@JudgementAmountMin money = NULL,
@JudgementAmountMax money = NULL,
@AssessedValueMin money = NULL,
@AssessedValueMax money = NULL,
@saledatestart Date = NULL,
@saledateend Date = NULL
AS
SELECT s.SaleId, s.CaseNumber, s.County, s.Mapsco, s.Plaintiff, s.Defendant,
s.Address, s.City, s.State, s.ZipCode, s.JudgementAmount, s.YearOfConstruction,
s.LegalDescription, s.AssessedValue
FROM Sale s
WHERE (s.City = @City OR @City IS NULL)
AND (s.ZipCode = @ZipCode OR @ZipCode IS NULL)
AND (s.County = @County OR @County IS NULL)
AND (s.JudgementAmount >= @JudgementAmountMin OR @JudgementAmountMin IS NULL)
AND (s.JudgementAmount <= @JudgementAmountMax OR @JudgementAmountMax IS NULL)
AND (s.AssessedValue >= @AssessedValueMin OR @JudgementAmountMin IS NULL)
AND (s.AssessedValue <= @JudgementAmountMax OR @JudgementAmountMax IS NULL)
AND (s.SaleDate >= @saledatestart OR @saledatestart IS NULL)
AND (s.SaleDate <= @saledateend OR @saledateend IS NULL)
ORDER BY s.SaleId
OPTION (RECOMPILE)
Using C# I would like to cause the sp to execute with parameters taken from user input from textboxes which may or may not contain a value. For example, I may have a value for city and for JudgementAmountMix and JudgementAmountMax only. I would like to have the query value the search variables from the textboxes.
I also need to have the result returned to the calling method for use in a WPF datagrid. I have spent days trying different examples on the web with no results and I am running into a deadline for delivery. I know that this has to be a pretty standard type of requirement for anyone working with SQL Server, I just have run out of time and run out of patience trying to find a solution. Any assistance would be appreciated and please provide as complete a solution as possible as I am fairly new at this.