VB.net 日期格式 Gridview dd/mm/yyyy
你好 我正在尝试更新 MS Access 数据库。我有一个带有我使用的日期的网格视图:
Dim tBox As TextBox = CType(gridStaff.Rows(e.RowIndex).FindControl("sDate"), TextBox)
然后我想从此文本框中获取值并将其分配给日期变量。
Dim test As Date = CDate(tBox.Text)
我遇到的问题是,现在当我将测试变量放入 sql 更新查询中时,它会以这种格式存储日期。 mm/dd/yyyy 而不是我想要的 dd/mm/yyyy 格式。
我尝试了不同的方法来格式化它,我在网上阅读但尚未成功。任何建议都会很棒!
谢谢
Hello
I'm trying to update a ms access database. I've got a gridview with a date that i use:
Dim tBox As TextBox = CType(gridStaff.Rows(e.RowIndex).FindControl("sDate"), TextBox)
I then want to take the value from this textbox and assign it to a date variable.
Dim test As Date = CDate(tBox.Text)
The problem I have is that now when I put test variable into my sql update query it stores the date in this format. mm/dd/yyyy instead of the dd/mm/yyyy format I want.
Ive tried different ways to format it I read online but to no success yet. Any advice would be great!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是从 tBox.Text 到 Date 的转换,还是在 sql 更新查询级别? -- 您或许应该为 sql 语句提供一个严格类型的参数。从 tBox.Text 转换为测试可能应该以文化感知方式完成:
'要转换的字符串和目标日期:
昏暗的日期字符串作为字符串=“02/15/2011”
Dim d As Date
' 转换字符串时指定英语/美国文化:
Dim cul As Globalization.CultureInfo = Globalization.CultureInfo.GetCultureInfo("en-US")
d = Date.Parse(dateString, cul)
您还可以依赖默认区域性,只需让 Date.Parse 完成工作而不指定区域性。
Is your problem the conversion from tBox.Text to Date, or is it at the sql update query level? -- You should probably give the sql statement a parameter with a strict type. Converting from tBox.Text into test should probably be done in a Culture aware manner:
'String to convert and target date:
Dim dateString As String = "02/15/2011"
Dim d As Date
' Specify English/US culture when converting string:
Dim cul As Globalization.CultureInfo = Globalization.CultureInfo.GetCultureInfo("en-US")
d = Date.Parse(dateString, cul)
You could also rely on the default culture and simply let Date.Parse do the job without specifying the culture.
请尝试使用
如果您的系统设置正确并且 CultureInfo.CurrentCulture 具有正确的日期格式,
or代替
CDate()
try using
or if your System is set up right and CultureInfo.CurrentCulture has the right date format,
instead of
CDate()