Search code examples
sqlms-accessoledb

Ole DB statement runs in Access but not in Visual Studios


I have the following statement and it returns my desired result in Access however in Visual Studio, I receive an error saying "; expected", what could be the problem?

var query = "SELECT Count(*) FROM usersTable WHERE (((usersTable.[uDateCreated]) Between DateAdd("d",-2,Now()) And Now()))";

Solution

  • You need to escape your quotes inside your string:

    " .. Between DateAdd(\"d\",-2 .. "
                         ^  ^ escape the quotes