[英]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):
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.