How to insert character code in C # query?
In the place where I indicate the date format:

OleDbCommand cmd = new OleDbCommand("SELECT top 1 task.[date_execute] FROM task where Format(Now(), "dd.mm.yyyy") = format(task.[date_execute], "dd.mm.yyyy") order by task.[date_execute] asc;"); 
  • one
    Either escape ( "\"" ) or use single quotes. - EvgeniyZ
  • Thank! Closed question - djoni

1 answer 1

For such purposes, there is shielding .
Each language has its own symbol for this purpose, in C # it is a backslash ( \ ).

Example:

 string valie = "Hello \"User\""; 

Your request with screening will be:

 "SELECT top 1 task.[date_execute] FROM task where Format(Now(), \"dd.mm.yyyy\") = format(task.[date_execute], \"dd.mm.yyyy\") order by task.[date_execute] asc ; " 

In most cases, double quotes can be replaced by single quotes, but this method does not work everywhere!
Example:

 string valie = "Hello 'User'";