I have an Access database table containing a row of dates in DateTime format. what I need to do is get all the distinct month names of the available dates into my asp.net page. For example if I have the following dates:
03-JAN-13
04-JAN-13
09-FEB-13
the sql query would give me the following month names: JAN and FEB.
After searching the web i found that the following sql query is supposed to give me what I need:
OleDbCommand cmd5 = new OleDbCommand("SELECT distinct DATENAME( 'mm', date_time) as MonthName from temperature ", cn);
but when I run my asp.net website, I get the following exception:
Exception Details: System.Data.OleDb.OleDbException: Undefined function 'DATENAME' in expression.
PS: afterwards I will put these string values in a dropdownlist (no problem with that step).
So can anybody tell me how to do it?
Thanks!
For Access, the syntax should be:
Because the
MonthNamefunction expects an Integer and theMonthfunction returns the Integer value of the Month.See here and here for complete details