VB .NET - 将'time'作为字符串输入数据库...但数据库附加日期! [英] VB .NET - Entering 'time' as a string into database... But database attaches a date!

查看:91
本文介绍了VB .NET - 将'time'作为字符串输入数据库...但数据库附加日期!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以在将Access数据库作为数据源添加到我的项目之后,我决定将特定表中的时间字段从日期/时间更改为字符串值,原因各种各样。我在原始数据库,项目的bin \Debug文件夹中复制的数据库和数据集中进行了此更改。所有的更改都得到了保存,一切都很好。


但是当我去向数据库中添加一个实际的时间字符串时(格式为12:00 PM),当我检查在数据库中该记录的字段中输入的值时,它也附有今天的日期(因此31/10/2007 12:00 PM)。我检查过我实际上正在进入一个'12:00 PM字符串进入现场,这很好。但由于某种原因,当它实际输入数据库时​​,附加了一个日期......即使该字段也是数据库中的字符串!


我真的没有想知道与此有什么关系...任何建议都是值得赞赏的。

Okay, so after adding an Access database as a data source to my project, I decided to change the ''time'' field in a particular table from date/time to a string value for various reasons. I made this change in the original database, the copied database in my project''s bin\Debug folder and the dataset. The changes were all saved and everything looked fine.

But then when I went to add an actual ''time'' string into the database (in the format 12:00 PM), when I checked the value entered in the field for that record in the database, it had today''s date attached to it as well (so 31/10/2007 12:00 PM). I checked that I was actually entering a ''12:00 PM'' string into the field, and that was fine. But for some reason, when it is actually entered in the database, a date is attached... Even though the field is a string in the database as well!

I really have no idea what the deal with this is... Any advice at all is appreciated.

推荐答案


好​​的,所以之后将Access数据库作为数据源添加到我的项目中,由于各种原因,我决定将特定表中的时间字段从日期/时间更改为字符串值。我在原始数据库,项目的bin \Debug文件夹中复制的数据库和数据集中进行了此更改。所有的更改都得到了保存,一切都很好。


但是当我去向数据库中添加一个实际的时间字符串时(格式为12:00 PM),当我检查在数据库中该记录的字段中输入的值时,它也附有今天的日期(因此31/10/2007 12:00 PM)。我检查过我实际上正在进入一个'12:00 PM字符串进入现场,这很好。但由于某种原因,当它实际输入数据库时​​,附加了一个日期......即使该字段也是数据库中的字符串!


我真的没有想知道与此有什么关系......任何建议都表示赞赏。
Okay, so after adding an Access database as a data source to my project, I decided to change the ''time'' field in a particular table from date/time to a string value for various reasons. I made this change in the original database, the copied database in my project''s bin\Debug folder and the dataset. The changes were all saved and everything looked fine.

But then when I went to add an actual ''time'' string into the database (in the format 12:00 PM), when I checked the value entered in the field for that record in the database, it had today''s date attached to it as well (so 31/10/2007 12:00 PM). I checked that I was actually entering a ''12:00 PM'' string into the field, and that was fine. But for some reason, when it is actually entered in the database, a date is attached... Even though the field is a string in the database as well!

I really have no idea what the deal with this is... Any advice at all is appreciated.



您是否有机会发布您使用的实际代码?

Any chance that you are going to post the actual code you used?


您好,

如果您在设计表格时已经进行了任何验证,请检查一下

类似验证或默认值。因为有可能,它会将日期附加到时间即使您只添加时间值。
Hi,

Please check that if you have put any validations while designing the table
like validations or default value.Because of which it is possible that , it will attach date to the time even if you add only time value.


好吧,程序正在完成它的工作(并且很难简单解释)。如果我在进入数据库之前检查它的值,它会显示它是我想要的确切格式的字符串(所以12:00 PM或其他)。但是当我打开数据库以查看输入的值时,它会在时间字段中显示此时间以及今天的日期。


例如,我有一个蒙版文本框,它接受格式为00:00的字符串和单选按钮,允许用户选择AM或PM。然后将该值作为数据库表'tblPrivateLesson'中的字段输入。

Well the thing is that the program is doing its job fine (and it''s pretty difficult to explain briefly). If I check the value right before it goes into the database, it shows that it''s a string in the exact format that I want (so 12:00 PM or whatever). But when I open the database to see what values got entered, it shows this time as well as today''s date in the ''time'' field.

For example, I have a masked text box that accepts a string in the format 00:00 and radio buttons that allow the user to select AM or PM. This value is then entered as a field in the database table ''tblPrivateLesson''.

展开 | 选择 | Wrap | 行号


这篇关于VB .NET - 将'time'作为字符串输入数据库...但数据库附加日期!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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