我写C#程序转换成一个统数据库,以XML,一切工作,除了本备忘录的领域是空白的。是不是有什么我错过了转换的那位?

我使用。净3.5sp1、视觉统9SP1OLE DB驱动程序。连串是好的,因为所有其他数据是被拉正常。

当我转换的系统的数据库到SQL服务器、备忘录场也是空白的没有,所以我不能转换的两倍。

有帮助吗?

解决方案

结束了我自己做一些工作,但也许它可以在将来帮助其他人:

        public static object GetDbaseOrFoxproRawValue(string DBPath, string TableName, string ColumnName, 
        string CompareColumnName, string CompareValue, bool CompareColumnIsAutoKey)
    {
        using (BinaryReader read = new BinaryReader(File.Open(
            Path.Combine(DBPath, TableName + ".dbf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
        {
            // Is it a type of file that I can handle?
            if (new byte[] { 0x02, 0x03, 0x30, 0x43, 0x63, 0x83, 0x8b,
                             0xcb, 0xf5, 0xfb }.Contains(read.ReadByte()))
            {
                // Skip date.
                read.BaseStream.Seek(3, SeekOrigin.Current);

                // Read useful datas...
                uint RecordCount = read.ReadUInt32();
                ushort FirstRecord = read.ReadUInt16();
                ushort RecordLength = read.ReadUInt16();
                int FieldCount = FirstRecord - 296 / 32;

                // Make sure things aren't stupid.
                ColumnName = ColumnName.ToLower();
                CompareColumnName = CompareColumnName.ToLower();

                // Find target column (field)
                string temp;
                UInt32 CompareFieldOffset = uint.MaxValue, FieldOffset = uint.MaxValue;
                byte CompareFieldLength = 0, FieldLength = 0;
                char FieldType = ' ';
                for (int i = 0; i < FieldCount; i++)
                {
                    read.BaseStream.Seek(32 + (i * 32), SeekOrigin.Begin);
                    temp = Encoding.ASCII.GetString(read.ReadBytes(11)).Replace("\0", "").ToLower();
                    if (temp == CompareColumnName)
                    {
                        read.ReadChar();
                        CompareFieldOffset = read.ReadUInt32();
                        CompareFieldLength = read.ReadByte();
                    }
                    if (temp == ColumnName)
                    {
                        FieldType = read.ReadChar();
                        FieldOffset = read.ReadUInt32();
                        FieldLength = read.ReadByte();
                    }

                    if (CompareFieldOffset != uint.MaxValue && FieldOffset != uint.MaxValue)
                        break;
                }

                // Make sure we can continue.
                if (CompareFieldOffset == uint.MaxValue || 
                    FieldOffset == uint.MaxValue) return null;

                // Iterate through each record to find the one we want.
                for (int index = 0; index < RecordCount; index++)
                {
                    read.BaseStream.Seek(FirstRecord + (index * RecordLength) + CompareFieldOffset, SeekOrigin.Begin);
                    temp = Encoding.Default.GetString(read.ReadBytes(CompareFieldLength)).Replace("\0", "");
                    if (temp == CompareValue)
                    {
                        read.BaseStream.Seek(FirstRecord + (index * RecordLength) + FieldOffset, SeekOrigin.Begin);
                        switch (FieldType)
                        {
                            case 'M':
                            case 'I': return read.ReadUInt32();
                            case 'C':
                            default: return Encoding.Default.GetString(read.ReadBytes(FieldLength)).Replace("\0", "");
                        }
                    }
                }
            }
            else
            {
                return null;
            }
        }

        return null;
    }

只需从中获取结果并将其用作备忘录文件的索引(使用MSDN文档,该代码非常简单)。

其他提示

我不太熟悉C#或统或SQL服务器,所以我不能给你太多的建议在这方面的工作。

然而,如果无法找到合适的司机,你可以考虑分析原始数据和备忘录的文件自己。另一个问题已处理与这样的:

什么是最简单的方法阅读统DBF文件从蟒蛇?

信不信由你,这些文件的格式是相当简单的分析应该你决定要自己写的C#分析器。这些规范都可以从微软:

我使用ODBC链接VFP 8表,备忘录字段没有问题。我不知道OLEDB是否不同。

您可能没有Visual FoxPro表。许多VFP系统使用与它们替换的FoxPro 2或dBase应用程序相同的表。您可以查看文件头或只是尝试其他ODBC驱动程序之一,看看它们是否有效。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top