微软的 Microsoft Text Driver 将文本视为浮动操作
使用.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用 schema.ini文件——这些可用于显式定义文本文件的格式,包括数据类型。
您的 schema.ini 文件最终可能看起来有点像:
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:
尝试使用 schema.ini
再见。
Try using schema.ini
Bye.