Thursday, May 31, 2012

VB. NET DAY function. 'Day' is a type and cannot be used as an expression.

The day function to retrieve the day part from a DATE data type is a very common function in VB.NET
usually I will use DAY(now) to retrieve the day part. which return 1 to 31 normally.


It is working well for all my ASP.NET project until recently I started a VB.NET project because I need to synchronize a local DB using HTTP to my server. Which I need a stand alone application for the local user to help me CLICK a button to sync some data. and further improve it to becomes a automated windows service. But before that you will get an error message 
'Day' is a type and cannot be used as an expression.


I was like WTF with this VB.NET, everything should be the same as ASP.NET
it is really a frustration to look around for solution.

So the only thing you need to do is to import that DAMN visual basic reference

Imports Microsoft.VisualBasic.DateAndTime


everything will go fine after that, I guess this import is a "DEFAULT" import for ASP.NET
VB.NET  application or VB.NET services do not have this default setting.



No comments:

Post a Comment