日期格式的一部分有误. [表达式(如果已知)=] [英] There was an error in a part of the date format. [ Expression (if known) = ]

查看:51
本文介绍了日期格式的一部分有误. [表达式(如果已知)=]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将日期保存在数据库的日期时间字段中.
我的变量将日期捕获为

Hi,
I am trying to save date in my database'' datetime field.
My variable catches date as

vrDteTimePprBgn As Date = Today.Date


然后我另存为


then I save it as

drNewRowMCQsAns.Item("DTE") = vrDteTimePprBgn


在运行时,出现错误
日期格式的一部分有误. [表达式(如果已知)=]
请指教.
谢谢


At runtime, I get error
There was an error in a part of the date format. [ Expression (if known) = ]
Please advise.
Thanks

推荐答案

首先
尽管Today.Date 可行,但我认为获得Date.Today
更正常 其次,您正在尝试将VB.net Date对象传递到数据库中,而我不知道您使用的是哪种类型的db等,因此您需要查看转换为db DateTime的合适方法.

最简单的操作可能只是将日期的字符串表示形式传递给数据库,并让它处理事务,除非您需要在其他地方使用变量,只需将其装箱并直接工作即可;

Firstly
Although Today.Date works, I think it is more normal to get Date.Today
secondly, you are trying to pass a VB.net Date object into the DB, which i don''t know what type of db etc, you are using, so you will need to look at the suitable methods to convert to db DateTime.

The easiest thing to do is may just to pass in a string representation of the date to the db, and let it take care of things, also unless you need the variable else where, just bin it and work directly;

drNewRowMCQsAns.item("DTE") = Date.Today.ToShortDateString



根据您所使用的数据库类型的不同,您可能必须在字符串后附加一组#号,例如



Depending also on the type of DB you are using, you may have to append a set of #''s to the string e.g.

drNewRowMCQsAns.item("DTE") = "#" & Date.Today.ToShortDateString & "#"




试一试,看看你过得怎么样.

正确的方法是按照本文中的示例使用基于参数的查询;
http://forums.asp.net/p/314258/314258.aspx [ ^ ]




Give that a go and see how you get on.

The proper way would be to use parameter based queries as per the example in this post;
http://forums.asp.net/p/314258/314258.aspx[^]


这篇关于日期格式的一部分有误. [表达式(如果已知)=]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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