Answered by:
How to query by a Date in a where statement for access db

Question
-
User-1188570427 posted
I want to perform a count statement on an access db. I keep on getting an error "System.Data.OleDb.OleDbException: No value given for one or more required parameter". I can't figure out exactly how to pass the date value.
date_selected = "#" + date_selected + "#"
Dim countsql As String = "SELECT count(*) FROM " + _
"tbllogin" + " WHERE ([date_in] = '" + date_selected + "') AND ([userid] = '" + userid + "')"
Saturday, January 15, 2011 11:56 PM
Answers
-
User-1188570427 posted
Here is the answer:
WHERE ([date_in] = " + "#" + date_selected + "#" + ") AND ([userid] = '" + userid + "')"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 16, 2011 2:38 AM
All replies
-
User-693248168 posted
I think the db Access takes the format YYYY-MM-DD format.
So you can change your query like this
date_selected = "#" + date_selected.ToString("yyyy-MM-dd") + "#"
Dim countsql As String = "SELECT count(*) FROM " + _
"tbllogin" + " WHERE ([date_in] = '" + date_selected + "') AND ([userid] = '" + userid + "')"Sunday, January 16, 2011 1:36 AM -
User-1188570427 posted
That did not work.
Sunday, January 16, 2011 2:10 AM -
User-1188570427 posted
Here is the answer:
WHERE ([date_in] = " + "#" + date_selected + "#" + ") AND ([userid] = '" + userid + "')"
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, January 16, 2011 2:38 AM -
User-1199946673 posted
All solutions war really not good practice. Start using parameterized queries:
http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access
http://www.mikesdotnetting.com/Article/92/MS-Access-Date-and-Time-with-ASP.NETMonday, January 17, 2011 3:30 AM