错误:字符串未被识别为有效的DateTime。 [英] error:the string was not recognized as a valid DateTime.

查看:153
本文介绍了错误:字符串未被识别为有效的DateTime。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试插入一个按钮被单击在gridview上的时间/日期,它会生成错误:字符串未被识别为有效的DateTime。有一个未知的单词从索引0 我已将文化改为en-US但它仍然无效。我实际创建了一些数据输入表后的日期/时间列,因此该列允许空值。这是我的代码:


InsertCommand =" INSERT INTO test101(姓氏,姓名,注册,日期/时间)价值(@姓,@姓,@注册,@ DateTime,getdate ())"


< Insert Parameters>< asp:Parameter DefaultValue = DateTime.Now()Type = DateTime Name =" DateTime" />< /插入参数>


有什么建议吗?

解决方案

你不应该使用DateTime。 Now()但是使用DateTime.Now,因为Now不是函数。


如果它不喜欢它,请尝试DateTime.Now.ToString()

你试过Now()吗?我似乎记得getDate首先返回当天的名字,所以取决于你的桌子的设计。



你不应该使用DateTime.Now()但是使用DateTime.Now,因为Now不是函数。


如果它不喜欢,请尝试DateTime.Now.ToString( )



现在错误显示将DateTime从字符转换为字符串时转换失败


hi all, i''m trying to insert the time/date a button was clicked on a gridview and it generates an error:the string was not recognized as a valid DateTime.There is an unknown word starting at index 0 i have changed the culture to en-US but it still doesn''t work. i actually created the date/time column after some data had been entered into the table so the column allows nulls. this is my code:

InsertCommand="INSERT INTO test101(Surname,Names,Registration,Date/Time)VALUES (@Surname, @Names, @Registration,@DateTime,getdate())"

<Insert Parameters><asp:Parameter DefaultValue= DateTime.Now() Type=DateTime Name="DateTime" /></Insert Parameters>

any suggestions?

解决方案

You shouldn''t be using DateTime.Now() but instead be using DateTime.Now, as Now is not a function.

If it doesn''t like that, try DateTime.Now.ToString()


Have you tried Now()? I seem to recall getDate returning the name of the day first, so depends on the design of your table.


You shouldn''t be using DateTime.Now() but instead be using DateTime.Now, as Now is not a function.

If it doesn''t like that, try DateTime.Now.ToString()

now the error says "conversion failed when converting DateTime from character to string"


这篇关于错误:字符串未被识别为有效的DateTime。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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