查找字段的DataReader对象数据类型 [英] Find the datatype of Field from DataReader object

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

问题描述

我有以下查询:

SqlCommand cmd = new SqlCommand("Select employee_id, 
          lastname, firstname from Employees", conn);

//Execute reader
SqlDataReader reader = cmd.ExecuteReader();

使用SqlDataReader的

,我只是想知道的数据类型字段:

using sqlDatareader, I just want to know the datatype field :

假设我想知道的领域EMPLOYEE_ID如何使用知道数据类型变量?

suppose i want to know the datatype of field employee_id how to know using reader variable ?

感谢

推荐答案

reader.GetFieldType(INT序)

将返回字段的.NET类型,而

will return the .NET type of the field, while:

reader.GetDataTypeName(INT序)

将返回重新presenting字段的数据类型,数据源的字符串(如 VARCHAR )。 GetFieldType 很可能是给你描述的用例更对你有用。

will return a string representing the data type of the field in the data source (e.g. varchar). GetFieldType is likely to be more useful to you given the use case you describe

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

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