I am trying to send this message through C# to an access database. The user input are two dates selected through a datePicker. The date picker itself is selected as short format. and the access db field is also selected as a short date time. following is my code
"SELECT PLADS,COUNT(*)AS Total FROM OptagetPladser " +
"WHERE( Dato Between #" + date_1 + "# AND #" + date_2 + "# AND Optaget= 0) " +
"GROUP BY PLADS HAVING Total >= " + diffResult;
The problem seems to be the between statement. I have tested using >= date 1 and i get all the results greater than date 1. I then try with just the results <= date 2 and this works but >=date 1 and and <= date 2 gives an empty answer
Try using parameters:
Using an established connection:
For OleDb, the parameters are based on an index of when they appear in the SQL string, hence, the “?” values have to be entered in the same order they appear in the query string.