1

我有一些 Foxpro 表,其中一个包含 Blob 字段。我知道存储在 Blob(一个 MapPoint 文件)中的数据类型,但我不知道如何提取它,因为我没有 FoxPro(我不能轻易获得它)。

有没有办法获取 .DBF 和 .FPT 文件并提取其中存储的 MapPoint 文件?

4

3 回答 3

1

您可以使用 C# 和 ADO.NET 将数据提取到文件中。这是一些示例代码:

using System;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace SaveFoxProMemoFieldAsFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = @"Provider=VFPOLEDB.1;Data Source=C:\data\;Collating Sequence=MACHINE;Null=Yes";

            string sqlSelect = "SELECT filedata FROM filelist";
            int fileNumber = 1;
            using (OleDbConnection connection = new OleDbConnection(connectionString))
            {
                using(OleDbCommand command = connection.CreateCommand())
                {
                    command.CommandText = sqlSelect;
                    command.CommandType = CommandType.Text;

                    try
                    {
                        connection.Open();
                        using(OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
                        {
                            if(reader.HasRows)
                            {
                                while(reader.Read())
                                {
                                    byte[] binaryData = (byte[])reader["filedata"];

                                    FileStream fs = new FileStream(string.Format(@"C:\data\file_{0}.pdf", fileNumber++), FileMode.OpenOrCreate, FileAccess.Write);
                                    fs.Write(binaryData, 0, binaryData.Length);
                                    fs.Close();
                                }
                            }
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
            }

            Console.WriteLine("Program execution complete");
            Console.WriteLine("Press any key to end");
            Console.ReadKey();
        }
    }
}

如果您需要 FoxPro 驱动程序,请访问Microsoft OLE DB Provider for Visual FoxPro 9.0 。

于 2011-11-24T21:33:56.973 回答
0

上一个链接显示了如何 从 C# 连接到 VFP。该答案实际上显示了与 OleDbProvider 的连接,这与 DaveB 的答案相似,但是,VFP 不是 SQLServer 连接并使用 VFP OleDbProvider 可在Microsoft 的 VFP 网站上获得

相互结合使用(连接到 VFP OleDB)和运行查询。连接字符串只需要指向数据所在的物理路径,就可以从该文件夹中的任意一个.dbf中查询。您不必显式连接到实际的“数据库”,因为 VFP 暗示路径是数据库的位置。

无论如何,与 Dave 一起提出的另一个问题应该能够让您的数据可用并将其写入流中。唯一需要注意的是,您正在编写的文件流也要确保它是二进制文件。否则,无论何时您写入一个作为 {enter} 键的字节,都可能会被强制写入尾随 {line feed}。很久以前,我发现在构建二维条码时编写二进制图像文件很困难,而且它变得一团糟。

于 2011-11-24T23:59:05.933 回答
0

我需要提取一些 PDF 文件,这些文件存储在我认为 FoxPro 的备忘录字段中。架构将该字段列为LONGVARCHAR

我可以使用提供的源代码,但需要更改 SQL,否则会出现转换错误。

如果我将 PDF 文件作为字符串拉出,只要遇到NULL \0BLOB 中的值,它就会被截断。

这是我使用的 SQL:

string sqlSelect = "SELECT cast(inc_rawdata as Blob) as inc_rawdata, inc_filename  FROM F2_522_SYS_MAP_FILES";
于 2017-09-11T17:24:29.793 回答