隐式转换错误 [英] Implicit conversion error

查看:83
本文介绍了隐式转换错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有人可以告诉我为什么会出现这种类型的错误,即不允许从数据类型datetime到int的隐式转换。 convert函数来运行这个查询。当我迁移到新数据库时,虽然所有列和数据类型都相同。



提前谢谢

Hi all,

Can anybody tell me why do i get this type of error i.e., "Implicit conversion from data type datetime to int is not allowed. Use the convert function to run this query." when i migrate to new database although all the columns and datatypes are same.

Thanks in advance

推荐答案

直接与int(long)关联的DateTime对象的属性是Ticks属性,因此如果要将数据转换为数字,请使用该属性。



出现错误原因是因为你为int指定了一些日期,这无论如何都是错误的,因为tick需要更多的空间并且必须是一个大的int,称为long(long int的short)因此int不符合数字它可以生成,因此它本质上不会工作,除非你告诉它如何。



有趣的是以下是可能的,虽然不推荐,因为它会给运行时错误最终运行常规日期:)



The property of a DateTime object which correlates directly to an int (long) is the "Ticks" property so if you want to cast a date to a number use that.

The error of cause appears because you assign some date to an int, which is anyway wrong as ticks need more space and have to be a big int, called long (short for long int) so the int doesn't fit the number it could generate and therefore it wont work in essence unless you tell it how.

Interesting the following is possible although not recommended because it will give runtime errors eventually running regular dates :)

var x = (int) DateTime.UtcNow.Ticks;

这篇关于隐式转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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