开发者

c# DateTime Not Valid in the Given Context

I posted a similar question but confusion set in so I feel the need to repost but with more clarity.

I am trying to insert into a database (SqlCompact3.5) colum which requires a DateTime datatype.

In order to get the current date & time i wish to use something开发者_StackOverflow社区 like this:

SqlParameter vetCreated = new SqlParameter("@vetCreated", SqlDbType.DateTime);
vetCreated.Value = DateTime.Now;

However this results in a compile error saying DateTime() is a 'method'. which is not valid in the given context.

Any ideas?

Link to Badly Asked Previous Question


Try changing DateTime.Now to System.DateTime.Now and see if it compiles now.


I have a hunch that you have DateTime method in your class. So when you call DateTime.Now compiler gets confused either you want to use DateTime class or method.

Prefix DateTime.Now with namespace System.DateTime.Now.


You probably have a function named DateTime() in your class.

Change that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜