First of all, you need to check the value of
DateTime.Now.Date.ToShortDateString()
, you may get a surprise, sometimes.
The answer depend on computer culture settings.
Use the debugger to see the value as the program runs.
-----
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.
The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
-----
Quote:
Select * from table where [Date]=CONVERT(VARCHAR,'" + DateTime.Now.Date.ToShortDateString() + "',111)"
Never do this, because it promote a user input to SQL command and can lead to a problem called SQL Injection.
SQL injection - Wikipedia[
^]
SQL Injection[
^]
The solution to SQL injection will also solve your problem as sql server will know that your date is a date.