C#DateTime误解 [英] c# DateTime Misunderstanding

查看:94
本文介绍了C#DateTime误解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OP下方的注释中,有一个私有对象DateTime(){throw new NotImplementedException(); } 溜进来。

In one of the comments below the OP mentions a private object DateTime() { throw new NotImplementedException(); } slipping in. It happens .

我有一个 DateTime SqlCe数据库中的字段。我希望添加创建行的时间,因此需要:

I have a DateTime field in a SqlCe database. I wish to add the time the row is created hence the need for:

DateTime now = DateTime.Now;

但是我得到的这个问题是,这是'一种无效的方法给定的上下文
我猜测它与静态有关,也许我在非静态函数中使用了它?

However this issue i am getting is that this is 'a method which is not valid in the given context'. Im guessing its something to do with it being static and im using it in a non static function perhaps ?

只需在同一线程中提问

SqlParameter Created = new SqlParameter("@Created", SqlDbType.DateTime);
**Created.Value = DateTime.Now; <--- gives error DateTime() is method which is not valid in the given context**
SqlCeCommand mySQLCommand = dbCon.CreateCommand();
mySQLCommand.CommandText = "INSERT into table (Created) VALUES (@Created)";
mySQLCommand.Parameters.Add(vetCreated);
mySQLCommand.ExecuteNonQuery(); 

这似乎是一个合理的列表命令,用于添加 DateTime 到数据库?

Does this seem like a resonable list commands to add DateTime to the database?

推荐答案

在这一行:

mySQLCommand.Parameters.Add(vetCreated);

我不知道 vetCreated 是什么,但我想这是根据错误消息判断的方法。

I don't know what vetCreated is, but I suppose that it's a method judging by the error message.

您应该在此处使用参数对象 Created 代替。

You should use your parameter object Created there instead.

这篇关于C#DateTime误解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆