简体   繁体   English

如何从.NET应用程序读取和写入Paradox 7.x数据库?

[英]How to read and write to a Paradox 7.x database from .NET app?

I develop .NET application (C#) and I need to read and update some data in a Paradox 7.x database. 我开发.NET应用程序(C#),并且需要读取和更新Paradox 7.x数据库中的某些数据。

According to Microsoft article for Paradox 7-8 no support is provided for OLEDB. 根据Microsoft针对Paradox 7-8的文章 ,不提供对OLEDB的支持。

According to another SO question reading is possible, but not writing. 根据另一种SO,可以阅读而不是写作。

So is there any approach (maybe some third-party library or some BDE wrapper) how can I read and write to Paradox 7.x database? 那么,有什么方法(也许是某些第三方库或某些BDE包装器)如何读写Paradox 7.x数据库?

UPDATE I've tried OleDB approach: 更新我尝试了OleDB方法:

var builder = new OleDbConnectionStringBuilder();
builder.DataSource = "D:\\MyBase\\";
builder.Provider = "Microsoft.Jet.OLEDB.4.0";
var connection = new OleDbConnection(builder.ToString() + ";Extended Properties=Paradox 5.x");
var command = new OleDbCommand("SELECT * FROM Planes", connection);

connection.Open();
using (var reader = command.ExecuteReader())
     if (reader.HasRows)
         while (reader.Read())
               listBox1.Items.Add(reader.GetString(2));

This one fails with OleDbException (expectable because my database has Paradox 7.x format): 这一次失败,并出现OleDbException(可能是因为我的数据库具有Paradox 7.x格式):

External table is not in the expected format 外部表格的格式不正确

If I change connecton string to Extended Properties=Paradox 7.x - that one fails with enother OleDbException (expectable because Paradox 7 is not supported by OLEDB according to Microsoft article)) 如果我将connecton字符串更改为Extended Properties=Paradox 7.x 7.x-那将失败,并出现另一个OleDbException(根据微软文章,这可能是因为OLEDB不支持Paradox 7)

Invalid operation 无效的操作

I've tried ODBC approach: 我已经尝试过ODBC方法:

var connectionString = "Driver={Microsoft Paradox Driver (*.db )};" 
                + "DriverID=538;Fil=Paradox 7.X;"
                + "DefaultDir=D:\\MyBase\\;"
                + "Dbq=D:\\MyBase\\;"
                + "CollatingSequence=ASCII;";

var connection = new OdbcConnection(connectionString);
var command = new OdbcCommand("SELECT * FROM Planes", connection);

connection.Open();
using (var reader = command.ExecuteReader())
      if (reader.HasRows)
            while (reader.Read())
                  listBox1.Items.Add(reader.GetString(2));

That one also fails with OdbcException 那也因为OdbcException而失败

ERROR [HY000] [Microsoft] [Paradox ODBC driver] External table is not in the expected format 错误[HY000] [Microsoft] [Paradox ODBC驱动程序]外部表的格式不正确

So nothing work nor now.. 所以现在什么都没有用。

So finally I managed read and even write Paradox 7.x database via Microsoft.Jet.OLEDB.4.0 (decpite of Microsoft tells us that Paradox 7-8 is not supported): 因此,最后我通过Microsoft.Jet.OLEDB.4.0来管理读甚至写 Paradox 7.x数据库(尽管Microsoft告诉我们不支持Paradox 7-8):

  1. Install AccessDatabaseEngine for Office 2007 (32bit) 安装用于Office 2007的AccessDatabaseEngine(32位)
  2. Install AccessDatabaseEngine for Office 2010 (32bit) (choose AccessDatabaseEngine.exe ) 安装Office 2010的AccessDatabaseEngine(32位) (选择AccessDatabaseEngine.exe
  3. Install BDE 5.1.1.1 (It's better to install somewhere like D:\\BDE) 安装BDE 5.1.1.1(最好安装在D:\\ BDE之类的位置)
  4. Via BDE Administrator change NET DIR from C:\\ to any folder, where you have write privileges (I've changed to D:\\BDE) 通过BDE管理员, 将NET DIR从C:\\更改为您具有写权限的任何文件夹(我已更改为D:\\ BDE)

After following code works like a charm 遵循以下代码后,就像一个魅力

var builder = new OleDbConnectionStringBuilder();
builder.Add("Provider", "Microsoft.Jet.OLEDB.4.0");
builder.Add("Data Source", @"D:\MyBase\");
builder.Add("Persist Security Info", "False");
builder.Add("Extended properties", "Paradox 7.x; HDR=YES");
var connection = new OleDbConnection(builder.Tostring()); 
var command = new OleDbCommand("SELECT * FROM Planes", connection);
//reading
connection.Open();
using (var reader = command.ExecuteReader())
     if (reader.HasRows)
         while (reader.Read())
               listBox1.Items.Add(reader.GetString(2));
//writing
command = new OleDbCommand("DELETE * FROM Planes", connection);
command.ExecuteNonQuery();
connection.Close();

Hope this information will help somebody like me. 希望这些信息能对像我这样的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是 .Net 类型相当于 Paradox 数据库中的时间 - What is the .Net type equivalent to Time in Paradox Database 如何从.NET中的x行读取文件 - How to read a file from the x line in .NET 如何通过ASP.NET Webpart中的Kentico 7.x API对用户进行身份验证? - How to authenticate user via Kentico 7.x API in ASP.NET webpart? WindowPhone 7.x | 当应用程序进入后台时如何正确关闭/暂停视频录制 - WindowPhone 7.x | How to correctly close/pause video recording when app going to background 如何从.Net读取第2版Sqlite数据库? - How to read a Version 2 Sqlite database from .Net? 如何在 dot net 标准应用程序中使用 Dapper 从数据库中读取块中的文件 - How to read file in chunks from database with Dapper in dot net standard app 如何从数据库读取数据并将其写入txt文件? - How to read data from database & write it on a txt file? 如何从控制台应用程序(C#)读/写到SQL数据库 - How to Read/Write to SQL database from console application (C#) 如何从数据库读取并使用C#写入文本文件? - How to read from database and write into text file with C#? 使应用程序可用于Windows Phone 7.x和8 - Making an App available for both Windows Phone 7.x and 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM