问题描述
我有一个我相信是由Clipper创建的数据库文件,但不能肯定地说(我有用于索引的.ntx文件,我知道这是Clipper使用的文件).我正在尝试创建一个C#应用程序,该应用程序将使用System.Data.OleDB命名空间读取此数据库.
I have a database file that I beleive was created with Clipper but can't say for sure (I have .ntx files for indexes which I understand is what Clipper uses). I am trying to create a C# application that will read this database using the System.Data.OleDB namespace.
在大多数情况下,我可以成功读取表的内容,其中一个字段是我无法读取的.此字段称为CTRLNUMS,定义为CHAR(750).我已经阅读了许多通过Google搜索发现的文章,这些文章建议大于255个字符的字段必须通过与正常分配给字符串变量不同的过程来读取.到目前为止,我在找到的方法上还没有成功.
For the most part I can sucessfully read the contents of the tables there is one field that I cannot. This field called CTRLNUMS that is defined as a CHAR(750). I have read various articles found through Google searches that suggest field larger than 255 chars have to be read through a different process than the normal assignment to a string variable. So far I have not been successful in an approach that I have found.
以下是我用来读取表的示例代码片段,其中包括我用来读取CTRLNUMS字段的两个选项.这两个选项都导致返回238个字符,即使该字段中存储了750个字符也是如此.
The following is a sample code snippet I am using to read the table and includes two options I used to read the CTRLNUMS field. Both options resulted in 238 characters being returned even though there is 750 characters stored in the field.
这是我的连接字符串:
Provider = Microsoft.Jet.OLEDB.4.0;数据源= c:\ datadir;扩展属性= DBASE IV;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\datadir;Extended Properties=DBASE IV;
有人可以告诉我从DBF文件读取较大字段的秘密吗?
Can anyone tell me the secret to reading larger fields from a DBF file?
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
conn.Open();
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = string.Format("SELECT ITEM,CTRLNUMS FROM STUFF WHERE ITEM = '{0}'", stuffId);
using (OleDbDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
stuff.StuffId = dr["ITEM"].ToString();
// OPTION 1
string ctrlNums = dr["CTRLNUMS"].ToString();
// OPTION 2
char[] buffer = new char[750];
int index = 0;
int readSize = 5;
while (index < 750)
{
long charsRead = dr.GetChars(dr.GetOrdinal("CTRLNUMS"), index, buffer, index, readSize);
index += (int)charsRead;
if (charsRead < readSize)
{
break;
}
}
}
}
}
}
推荐答案
您可以在此处找到有关DBF结构的描述: http://www.dbf2002.com/dbf-file-format.html
You can find a description of the DBF structure here: http://www.dbf2002.com/dbf-file-format.html
我认为Clipper过去所做的就是修改Field结构,以便在Character字段中,小数位保留该大小的高位字节,因此Character字段的大小实际上是256 * Decimals + Size.
What I think Clipper used to do was modify the Field structure so that, in Character fields, the Decimal Places held the high-order byte of the size, so Character field sizes were really 256*Decimals+Size.
我可能有一个读取dbfs的C#类(本机不是ADO/DAO),可以对其进行修改以处理这种情况.让我知道您是否有兴趣.
I may have a C# class that reads dbfs (natively, not ADO/DAO), it could be modified to handle this case. Let me know if you're interested.
这篇关于DBF大字符字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!