如何阅读dBASE文件并应用不同的解码? [英] How do i read a dbase file and apply different decoding?

查看:200
本文介绍了如何阅读dBASE文件并应用不同的解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DBF文件endcoded为866代码页(DOS)



使用下面的代码,我想读它。
问题是,字符串作为如果该文件是在代码页1252
到目前为止,我已经检查了SO和其他论坛的其他问题,没有运气我得到的形成。
寻找在炎热到propperly阅读它的想法。

  VAR的ConnectionString = @供应商= Microsoft.Jet.OLEDB .4.0;数据源= C:\PathtoFile\;扩展属性=dBase的5.0 
变种dBaseConnection =新System.Data.OleDb.OleDbConnection(的ConnectionString);

dBaseConnection.Open();

变种dBaseCommand =新System.Data.OleDb.OleDbCommand(SELECT * FROM文件名,dBaseConnection);
VAR dBaseDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess);


,而(dBaseDataReader.Read()){

Encoding.GetEncoding(866).GetString(Encoding.GetEncoding(1252).GetBytes(dBaseDataReader.GetString (2))转储(); //不利于
}


解决方案

在哪里是什么其他的文件扩展名是在相同的文件夹(例如FPT / CDX / IDX / NTX)文件?那应该给我们一个线索,无论是VFP或dBASE或快船还是其他什么东西。



如果它的Visual FoxPro(VFP)的数据,那么你应该从安装的 http://www.microsoft.com/en-gb/download/details.aspx?id=14839 ,并使用一个从 http://www.connectionstrings.com/采取以下连接字符串。可视的FoxPro#VFP-OLE-DB提供商



数据库容器(.DBC):

 提供程序= vfpoledb;数据源= C:\MyDbFolder\MyDbContainer.dbc;整理顺序=机; 



免费表目录:

 提供程序= vfpoledb;数据源= C:\MyDataDirectory\;整理顺序=一般; 

连接到一个单一的DBF文件:

 提供程序= vfpoledb;数据源= C:\MyDataDirectory\MyTable.dbf;整理顺序=机; 



http://msdn.microsoft.com/en-us/library/aa975609%28v=vs.71%29的.aspx



出于兴趣你怎么知道它被编码为代码页866?字节在Visual FoxPro dBFS的商店在偏移29的代码页标记。请参见 http://msdn.microsoft.com/ EN-US /库/ aa975386%28V = vs.71%29.aspx


I have a dbf file endcoded as 866 codepage (DOS)

Using the code below, I'm trying to read it. Problem is that strings I get are formed as if the file was in code page 1252. I've checked other questions on SO and other forums with no luck so far. Looking for ideas on hot to read it propperly.

var ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PathtoFile\;Extended Properties=""dBase 5.0""";
var  dBaseConnection = new System.Data.OleDb.OleDbConnection(ConnectionString );

dBaseConnection.Open();

var dBaseCommand = new System.Data.OleDb.OleDbCommand("SELECT * FROM FileName",dBaseConnection);
var dBaseDataReader =  dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess);


while( dBaseDataReader.Read()){

Encoding.GetEncoding(866).GetString(Encoding.GetEncoding(1252).GetBytes(dBaseDataReader.GetString(2)).Dump();  // Does not help 
}

解决方案

Where is the file from? What other file extensions are in the same folder (eg FPT/CDX/IDX/NTX)? That should give us a clue as to whether it is VFP or dBase or Clipper or something else.

If it's Visual Foxpro (VFP) data then you should install the VFPOLEDB provider from http://www.microsoft.com/en-gb/download/details.aspx?id=14839 and use one of the following connection strings taken from http://www.connectionstrings.com/visual-foxpro#vfp-ole-db-provider.

Database container (.DBC):

Provider=vfpoledb;Data Source=C:\MyDbFolder\MyDbContainer.dbc;Collating Sequence=machine;

Free table directory:

Provider=vfpoledb;Data Source=C:\MyDataDirectory\;Collating Sequence=general;

Connect to a single DBF-file:

Provider=vfpoledb;Data Source=C:\MyDataDirectory\MyTable.dbf;Collating Sequence=machine;

More info on the VFPOLEDB provider at http://msdn.microsoft.com/en-us/library/aa975609%28v=vs.71%29.aspx

Out of interest how do you know it is encoded as codepage 866? The byte at offset 29 in Visual Foxpro DBFs stores the codepage mark. See http://msdn.microsoft.com/en-us/library/aa975386%28v=vs.71%29.aspx

这篇关于如何阅读dBASE文件并应用不同的解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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