SQL和Visual Basic中的时间数据类型 [英] Time data type in sql and visual basic
问题描述
大家好,感谢那些以前回答过我的问题的人,您对我有很大帮助:)
无论如何,这是我今天的问题:
因此,我有一个带有time(7)字段的数据库表,并且我正在使用Visual Basic 2010 Express与数据库进行交互.
当我使用此代码时:
Hi guys and thanks to those folks who have answered my questions before, you are a great help :)
Anyway here''s my Q for today:
So I have a database table with a time(7) field and I am using visual basic 2010 express to interface with the DB.
when I use this code :
Time_StampTextBox.Text = Date.Now.TimeOfDay.ToString
我得到此结果
I get this result
08:18:01.8205871
,不需要尾随的7位数字
我尝试使用此代码:
, the trailing 7 digits are not wanted
I tried using this code:
Dim Arg1 = Date.Now.ToShortTimeString
Time_StampTextBox.Text = Arg1
我得到了8:18 AM,这很完美,但是DB.table不会将其接受到表中.
我没有收到错误消息,??
也尝试过
and I get 8:18 AM which is perfect, but the DB.table wont accept it into the table
and I dont get an error message, ??
also tried this
Format(Arg1, "h:m:s")
,但我所得到的只是"h:m:s"
与字段定义??中的数字7或其他有关吗?
谢谢大家:)
but all i got was "h:m:s"
is it to do with the number 7 in the field definition ??, or somthing else?
thanks guys :)
推荐答案
您应该考虑将日期存储在单独的变量中:
You should consider storing the date in a separate variable:
Dim ToDay as new DateTime
ToDay = DateTime.Now
textBox1.Text = ToDay.ToString("HH:mm:ss")
请参阅Microsoft文档:
http://msdn.microsoft.com/en-us/library/system.datetime. today.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx [ ^ ]
要存储日期,您只需使用ToDay.如果要更改时间,则应考虑使用DateTime选择器:
http://msdn.microsoft.com/en-us/library/ms229631.aspx [ ^ ]
See microsoft documentation:
http://msdn.microsoft.com/en-us/library/system.datetime.today.aspx[^]
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^]
And to store the date you simply use ToDay. If you want to change the time you should consider using a DateTime picker:
http://msdn.microsoft.com/en-us/library/ms229631.aspx[^]
这篇关于SQL和Visual Basic中的时间数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!