微软的 Microsoft Text Driver 将文本视为浮动操作

发布于 2024-08-02 10:44:56 字数 713 浏览 0 评论 0原文

使用.NET,

我有一个包含逗号分隔数据的文本文件。其中一列由如下文本组成: 1997/020269/07

现在,当我使用 OdbcCommand 进行选择时,字符串被视为浮点数,并且返回“答案”而不是实际文本!

我怎样才能得到实际的文本?我是否将被迫手动解析文件?

希望有人可以帮助...拜托?! :)

编辑:也许是一些代码? :)

string strConnString =
            @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + _FilePath +
            @"; Extensions=asc,csv,tab,txt;Persist Security Info=False";

var conn = new System.Data.Odbc.OdbcConnection(strConnString);

var cmd = new System.Data.Odbc.OdbcCommand("select MyColumn from TextFile.txt", conn);
var reader = cmd.ExecuteReader();


while (reader.Read())
{ Console.WriteLine(reader["MyColumn"]); }

这将返回 0.014074977 而不是 1997/020269/07

Using .NET

I have a text file with comma separated data. One of the columns consists of text like the following : 1997/020269/07

Now when I do a select with an OdbcCommand the string is seen as a float and it returns the 'answer' instead of the actual text!

How can I get the actual text? Am I going to be forced to parsing the file manually?

Hope someone can help...please?! :)

Edit: Some code maybe? :)

string strConnString =
            @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + _FilePath +
            @"; Extensions=asc,csv,tab,txt;Persist Security Info=False";

var conn = new System.Data.Odbc.OdbcConnection(strConnString);

var cmd = new System.Data.Odbc.OdbcCommand("select MyColumn from TextFile.txt", conn);
var reader = cmd.ExecuteReader();


while (reader.Read())
{ Console.WriteLine(reader["MyColumn"]); }

This returns 0.014074977 instead of 1997/020269/07

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不会写诗 2024-08-09 10:44:56

您是否尝试过使用 schema.ini文件——这些可用于显式定义文本文件的格式,包括数据类型。

您的 schema.ini 文件最终可能看起来有点像:

[sourcefilename.txt]
ColNameHeader=true
Format=CSVDelimited
Col1=MyColumn Text Width 14
Col2=...

Have you tried using a schema.ini file -- these can be used to explicitly define the format of the text file, including data types.

Your schema.ini file might end up looking a little like:

[sourcefilename.txt]
ColNameHeader=true
Format=CSVDelimited
Col1=MyColumn Text Width 14
Col2=...
深海不蓝 2024-08-09 10:44:56

尝试使用 schema.ini

[yourfile.txt]
ColNameHeader=false
MaxScanRows=0
Format=FixedLength
Col1=MyColumn Text Width 20

再见。

Try using schema.ini

[yourfile.txt]
ColNameHeader=false
MaxScanRows=0
Format=FixedLength
Col1=MyColumn Text Width 20

Bye.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文