从文本框到datagridview的插入日期显示错误的格式?我想显示日期dd / mm / yyyy格式。 [英] Inserted date from textbox to datagridview showing wrong format ? I want to show date dd/mm/yyyy format.

查看:84
本文介绍了从文本框到datagridview的插入日期显示错误的格式?我想显示日期dd / mm / yyyy格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在日期格式的更新命令中做了哪些更改?



我尝试了什么:



i我正在使用

what changes i do in update command for Date format ?

What I have tried:

i am using

Val(TextBox2.Text)
'textbox2 contains date

推荐答案

数据库中的DateTime值没有格式这样的东西。显示日期时应用格式,并且您可以控制该格式。



如果您将日期保存为数据库中的文本,那么您肯定是做错了。切勿将DateTime值保存为文本。始终为数据使用正确的日期类型。
There is no such thing as a "format" for a DateTime value in a database. The format is applied when the date is displayed, and you have control over that.

If you're saving dates as text in your database, you're most assuredly doing it wrong. NEVER save DateTime values as text. Always use the proper date type for your data.


对于将字符串解析为值(整数,实数,日期等等)相关的所有内容,应始终使用目标valuetype的 TryParse 方法。

在您的示例中,那将是:

For everything that is related to parsing a string to a value (integers, reals, dates, etc...), you should always use the TryParse method of the target valuetype.
In your example, that would be:
Dim myDate As DateTime
If (DateTime.TryParse(TextBox2.Text, myDate))
   '' DateTime correct format
Else
   '' DateTime incorrect format
End If



TryParseExact 方法可让您更好地控制输入格式。

DateTime.TryParse方法 [ ^ ]

DateTime.TryParseExact Method [ ^ ]


The TryParseExact method gives you even more control on the input format.
DateTime.TryParse Method[^]
DateTime.TryParseExact Method[^]


这篇关于从文本框到datagridview的插入日期显示错误的格式?我想显示日期dd / mm / yyyy格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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