Lets work backwards here – your stored proc will never work, you have not specified a field for the where
, and it has 2 missing close parentheses.
select * from MyTable
where between CAST(@startDate AS VARCHAR(100) and CAST(@EndDateAS VARCHAR(100)
should be
select * from MyTable
where SOMEFIELD between CAST(@startDate AS VARCHAR(100)) and CAST(@EndDateAS VARCHAR(100))
In addition, the BETWEEN
keyword when working with dates must be actual dates – dates converted to VARCHAR
is unlikely to work.
Next up, using Convert.ToDateTime(startDate.Text)
is an error-prone way to convert to a date from a string. Instead you should call DateTime.ParseExact
(or, more appropriately TryParseExact
) specifying the format to use.
1
solved C# DateTime not working for MSSQL stored procedure [closed]