DataReader具有错误的架构/数据类型 [英] DataReader has wrong schema/data types

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

问题描述

我们正在使用OleDbDataReader将CSV文件转换为XML。当我们获取每行的值时,会丢失一些值,因为给列提供了错误的数据类型。具体来说,一列被视为十进制类型,但它应该是一个字符串。

我们不能强制执行一个模式,因为我们可以有一个或多个可选列,并且数据可能需要也可能不需要字段。

有什么方法可以强制一切都成为一个字符串?无论如何,一旦被读取,所有内容都会被转换为正确的对象类型。

另一种选择是强制所有文本列在它们周围加上引号,这可能会给用户带来不便,并且与我们软件的第一个版本。

谢谢。

We're transforming a CSV file to XML using the OleDbDataReader.  When we're getting the values for each row, some of the values are missing because the wrong data type is given to the column.  Specifically, a column is being seen as a decimal type, but it should be a string.

We cannot enforce a schema because we can have one or more optional columns and the data may or may not be required in the fields.

Is there any way I can force everything to be a string?  Everything just gets cast into it's correct object type once it's been read anyways.

An alternative option to this is to force all text columns to have quotes around them, which could cause inconvenience for the users and a difference from the first version of our software.

Thanks.

推荐答案

您使用Jet OLEDB提供程序读取CSV吗?如果您这样做,那么您可能使用schema.ini文件来描述列的数据类型。将类型设置为schema.ini文件中的字符串将为您执行此操作。另一种选择是尝试在连接字符串的扩展属性部分中使用IMAX = 1属性设置。 IMAX = 1强制Jet将所有值视为字符串。它在您从Excel查询数据时有效,但我从未尝试将此选项与CSV或任何其他文件一起使用。


这篇关于DataReader具有错误的架构/数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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