Never do this:
cm = new SqlCommand("select * from vwStockIn where cast(sdate as date) between '" + dt1.Value.ToShortDateString() + "' and '" + dt2.Value.ToShortDateString() + "' and status like 'Done'", cn);
Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
DROP TABLE MyTable;
A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Don't do this:
THat just introduces a layer of extra complexity as you convert to a string based on the your computer settings, and SQL converts back to a DATE based on its settings.
Instead, pass the DateTime value directly:
And no conversions are required.
Unless of course your DB column is storing date information in a VARCHAR or NVARCHAR column instead of DATE, DATETIME, or DATETIME2 in which case you need to change that or your comparisons will not work correctly anyway.
Then, look at the rest of your SQL:
cm = new SqlCommand("select * from vwStockIn where cast(sdate as date) between @sdate and @sdate1 and status like 'Bitti'", cn);
LIKE is an operator that needs wildcards: without them it's identical to "=" but slower.
You could try:
which will find anything with "Bitti" in it.
Then, this worries me:
...WHERE CAST(sdateAS DATE)...
which implies that you are
storing date info in a VARCHAR or NVARCHAR column, and that's a bad idea, because when you try to use it you have to convert it to a date to do anything - if you don't then a string based comparison is used, and that gives a result solely based on the first pair of different characters. Which means that sorting and comparing does not use date order: 01-12-2020 is before 31-01-2000. And ... it relies on your data never getting "bad data", which is unlikely, and which includes every computer inserting date info using the same settings ...
If you are, change your DB