如何检查数据类型 [英] how to check datatype

查看:107
本文介绍了如何检查数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想使用c#检查excel列的数据类型.实际上我现在正在使用字符串生成器(附加查询)在sql中导入excel文件,现在我要检查包含的所有列的数据类型.

请帮忙

在此先感谢
sanjeev

Hello All,

I want to check the data type of excel column using c#. Actually I am importing excel file in sql using string builder(appending a query) now i want to check data type for all the column included.

please help

thanks in advance
sanjeev

推荐答案

获取C#手册并签出运算符isas.

运算符is返回布尔值(如果这是正确的类型,则返回true),并且as对所需类型执行动态类型转换,如果运行时类型与所需类型不兼容,则返回null.所需的类型可以是接口.

请记住,在两个运算符中都考虑了继承.它检查变量是否与赋值兼容,而不是与所需类型相同的类型.因此,与将GetType()和typeof的结果进行比较相比,它具有灵活性-仅适用于相同类型.

另外,如果运算符as是原始类型或枚举类型,则它以变量的装箱式形式返回.

—SA
Get a C# manual and check out operators is and as.

The operator is returns Boolean value (true if the this is the right type), and as performs the dynamic typecast to required type which returns null if the run time type is incompatible with the required type. The required type can be interface.

Remember, in both operators inheritance is taken into account; it checks if the variable is assignment-compatible, not of the type identical to the required type. For this reason, it''s flexible, in contrast to comparing the result of GetType() with typeof — it works only for identical types.

Also, operator as returns a boxed form of the variable if it is of primitive or enumeration type.

—SA


IMO,Excel列没有数据类型.您几乎可以在任何列中键入任何内容(只要没有验证即可).从excel到SQL读取列时,有责任为目标列分配适当的数据类型并解析源列,以检查是否存在数据类型不匹配.
IMO, excel columns do not have data types. You can pretty much type whatever in any column (as long as there is not validation). When reading columns from excel to SQL, it becomes your duty to assign appropriate data types to the target columns and parse the source columns to check if there is a data type mismatch.


这篇关于如何检查数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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