简体   繁体   English

从字符串转换日期和/或时间时转换失败

[英]Conversion failed when converting date and/or time from character string

I have a gridview and sqldatasource. 我有一个gridview和sqldatasource。 In my regional settings in cp , date format is set to dd.MM.yyyy . 在我的cp区域设置中,日期格式设置为dd.MM.yyyy。

I have in my gridview a column with type date. 我在gridview中有一列类型为date的列。 In the gridview if I set a value to the cell in format dd.MM.yyyy 在gridview中,如果我以dd.MM.yyyy格式为单元格设置一个值

 `I get Conversion failed when converting date and/or time from character string`.

But if I type a date in format MM.dd.yyyy it works , but I don't really understand why it happenes? 但是,如果我以MM.dd.yyyy格式输入日期,则可以正常运行,但我真的不明白为什么会这样吗? and also If I set dd.MM.yyyy date format , manually in the table, it works. 并且如果我在表中手动设置dd.MM.yyyy日期格式,它也可以工作。

The column is itemtemplate and the control of the column wasn't edited . 该列是itemtemplate,并且该列的控件未编辑。

mm refers to minutes MM refers to the day. mm代表分钟MM代表天。 here is one reference on different formats available: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm 这是有关不同格式的一种参考: http : //www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm

myDate.ToString("dd-MM-yyyy")

请参阅此处: 如何在C#中将日期格式转换为DD-MM-YYYY

You need to specify the format of date into GridView. 您需要在GridView中指定日期格式。

 <asp:BoundField DataField="fieldname" HeaderText="Header text" ReadOnly="True"
                                                        SortExpression="fieldname" HtmlEncode="False" DataFormatString="{0:d}" / >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and /or time from character string 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and /or time from character string 从字符串错误4转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string error 4 错误“从字符串转换日期和/或时间时转换失败” - Error “Conversion failed when converting date and/or time from character string” 从字符串转换日期和/或时间时,DateTime转换失败 - DateTime conversion failed when converting date and/or time from character string 问题:从字符串转换日期和/或时间时转换失败 - Problem: Conversion failed when converting date and/or time from character string 从字符串#2转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string #2 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string 从Winforms中的字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string in winforms 从字符串转换日期和/或时间时转换失败 - Conversion failed when converting date and/or time from character string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM