---
title: "C#无法对Paradox数据库进行操作的解决办法"
author: "csstome"
date: "2007-12-25T00:40:00Z"
tags: []
slug: "c-paradox"
draft: false
lastmod: "2007-12-25T00:40:00Z"
id: 1033161
url: "https://csstome.iteye.com/blog/1033161"
---

用Delphi自带的Database Desktop工具打开db文件，编辑表，给某字段建立索引就可以了，会生成一个xxx.px索引文件

参考如下文档，其中4里面的第二条就是了  
[http://support.microsoft.com/kb/q175168/](http://support.microsoft.com/kb/q175168/)

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) 4.最后一个问题和替代方法适用于所有SQL数据源。违反数据库的引用完整性的SQL语句可以导致出现此错误。下面是一些最常见的失败的查询：  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) •其中最简单的一组查询是以下您无法更改的查询：UniqueValue属性设置为Yes的交叉表查询、SQL传递查询、联合查询或更新（即生成表）操作查询。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) •另一种非常常见的原因是联接包含的链接ODBC表的索引不是唯一的。在这种情况下，SQL无法保证表中的记录是唯一，该表中字段的值将随查询发生更改。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) •有一种原因确实有可靠的替代方法。如果您尝试更新“一对多”查询的“一”方的联接字段，操作将会失败，除非您启用级联更新。因为这样您就可以将引用完整性委托给JET引擎。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)

参考代码

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)string ConnectionString = @" Driver={MicrosoftParadoxDriver(\*.db)};DriverID=538;Fil=Paradox5.X;DefaultDir=C:Paradox;Dbq=C:Paradox;CollatingSequence=ASCII;PWD=; " ;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif) using (System.Data.Odbc.OdbcConnectionconn = new System.Data.Odbc.OdbcConnection(ConnectionString))  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif) ... {  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) conn.Open();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) using (System.Data.Odbc.OdbcCommandcommand = conn.CreateCommand())  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif) ... {  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) command.CommandText = " updatetestsetaa=14 " ;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) command.ExecuteNonQuery();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) command.CommandText = " select\*fromtest " ;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif) Console.WriteLine(command.ExecuteScalar());  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif) }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif) }  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)