将varchar数据类型转换为smalldatetime数据类型会导致超出范围的值. [英] The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.

查看:423
本文介绍了将varchar数据类型转换为smalldatetime数据类型会导致超出范围的值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我遇到了这个奇怪的问题:
我的数据库中有一个表,我为此添加了行.
我添加2行完美.每次添加后,我都使用DataAdapter.Fill()填充DataTable.

比起第三次我得到这个奇怪的执行:The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.

问题是,我的数据库中没有任何varchar数据类型! 我的猜测是,因为我使用的是他"-我在区域设置"中设置的希伯来语语言,而不是将MSSQL设置为en-us.

没有人知道为什么会发生这种情况吗?

thx!

hi all,
i''ve encountered this weird problem:
i have a table in my database for which i add rows.
i add 2 rows perfect. after each addition i fill a DataTable using DataAdapter.Fill().

than, at the 3rd time i get this weird execption:The conversion of a varchar data type to a smalldatetime data type resulted in an out-of-range value.

the thing is, i don''t have any varchar datatype in any of my database!!!
my guess is that, because i am using "he" - which is hebrew language set on my "Regional Settings", as opposed to the MSSQL set to en-us.

does anyone has a clue why this happens??

thx!

推荐答案

好,现在解决了! (经过几个小时的头痛...)

显然,当我刚刚学习C#时,我写了一条SQL语句:
"... startDate< =" [startDate]''..."
然后用DateTime的字符串表示形式替换[startDate].这就是varchar怪异行为的原因.

还是谢谢!
ok, it is now solved! (after some hours of headache...)

apparantely, when i''ve just learned C# i wrote a SQL statement:
"... startDate<=''[startDate]''..."
and than replaced the: [startDate] with a string representation of a DateTime. that was the reason of the varchar weird behavior.


thx anyway!


团队;
Sql Server的默认日期和时间格式为mm/dd/yyyy ... e.g(例如2009年12月1日12:00:00 AM)
您正在使用"he"-这是我在区域设置"中设置的希伯来语,而不是将MSSQL设置为en-us.

因此,我认为格式化转换问题请在dbuge模式下检查,如果它
true编写一个函数,该函数将输入日期作为参数并将其收敛.甲壳虫.
DateTime dt = getDate(txtRegdate.Text);


DateTime getDate(string dt)
{
试试
{
如果(!(dt.Trim().Length == 0))
{
\\您的逻辑根据要求
}
其他
返回DateTime.MinValue;
}
catch(ex异常)
{
返回DateTime.MinValue;
}

}


谢谢
Prasanta Kumar Pradhan
Hi Team;
The Defult date & Time Formate of Sql Server is mm/dd/yyyy...e.g(12/1/2009 12:00:00 AM)
Your are useing "he" - which is hebrew language set on my "Regional Settings", as opposed to the MSSQL set to en-us.

So i thing the Formate conversion Problem plese check in dbuge mode if it
true write a function that take the input date as a parameter & conver it to appe. formate.
DateTime dt = getDate(txtRegdate.Text);


DateTime getDate(string dt)
{
try
{
if (!(dt.Trim().Length == 0))
{
\\ Yor Logic As per the requirement
}
else
return DateTime.MinValue;
}
catch(Exception ex)
{
return DateTime.MinValue;
}

}


Thank''s
Prasanta Kumar Pradhan


这篇关于将varchar数据类型转换为smalldatetime数据类型会导致超出范围的值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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