C#中的悖论表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/304996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Paradox Tables in C#
提问by
I'm trying to read a Paradox 5 table into a dataset or simular data structure with the view to putting it into an SQL server 2005 table. I've trawled google and SO but with not much luck. I've tried ODBC:
我正在尝试将 Paradox 5 表读入数据集或模拟数据结构中,以便将其放入 SQL Server 2005 表中。我已经搜索了 google 和 SO,但运气不佳。我试过 ODBC:
public void ParadoxGet()
{
string ConnectionString = @"Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;DefaultDir=C:\Data\;Dbq=C:\Data\;CollatingSequence=ASCII;";
DataSet ds = new DataSet();
ds = GetDataSetFromAdapter(ds, ConnectionString, "SELECT * FROM Growth");
foreach (String s in ds.Tables[0].Rows)
{
Console.WriteLine(s);
}
}
public DataSet GetDataSetFromAdapter(DataSet dataSet, string connectionString, string queryString)
{
using (OdbcConnection connection = new OdbcConnection(connectionString))
{
OdbcDataAdapter adapter = new OdbcDataAdapter(queryString, connection);
connection.Open();
adapter.Fill(dataSet);
connection.Close();
}
return dataSet;
}
This just return the error
这只是返回错误
ERROR [HY000] [Microsoft][ODBC Paradox Driver] External table is not in the expected format.
错误 [HY000] [Microsoft][ODBC Paradox 驱动程序] 外部表不是预期的格式。
I've also tired OELDB (Jet 4.0) but get the same External table is not in the expected format error.
我也厌倦了 OELDB (Jet 4.0) 但得到相同的外部表不是预期的格式错误。
I have the DB file and the PX (of the Growth table) in the Data folder... Any help would be much appriciated.
我在数据文件夹中有 DB 文件和 PX(增长表的)...任何帮助都会非常有用。
回答by MysticSlayer
Maybe this will help you out,
也许这会帮助你,
http://support.microsoft.com/support/kb/articles/Q237/9/94.ASP?LN=EN-US&SD=SO&FR=1http://support.microsoft.com/support/kb/articles/Q230/1/26.ASP
http://support.microsoft.com/support/kb/articles/Q237/9/94.ASP?LN=EN-US&SD=SO&FR=1 http://support.microsoft.com/support/kb/articles/Q230 /1/26.ASP
It appears that the latest version of the Microsoft Jet Database Engine
看来 Microsoft Jet 数据库引擎的最新版本
(JDE) does not fully support Paradox unless the Borland Database Engine
(JDE) 不完全支持 Paradox,除非 Borland 数据库引擎
(BDE) is also installed.
(BDE) 也已安装。
回答by ahockley
This isn't an answer, but more of a question: any particular reason you're trying to use C# to do the data manipulation as opposed to using SQL Server tools to load the data directly? Something like DTS or SSIS would seem like a better tool for the job.
这不是答案,而是更多的问题:您尝试使用 C# 进行数据操作而不是使用 SQL Server 工具直接加载数据的任何特殊原因?DTS 或 SSIS 之类的东西似乎是完成这项工作的更好工具。
回答by ahockley
Thanks, I'll give that a try. I wanted to use C# so I can put it on some web pages without the extra set of putting it in SQL server.
谢谢,我试试看。我想使用 C#,所以我可以把它放在一些网页上,而不需要额外的把它放在 SQL 服务器中。
回答by user994887
Try to Run all The Applications with the "Run As Administrator" privileges especially run the VS.NET with "Run As Administrator "... and I am sure your problem get solved
尝试使用“以管理员身份运行”权限运行所有应用程序,尤其是使用“以管理员身份运行”运行 VS.NET ......我相信你的问题得到解决
回答by Ivan Golovin
I've had the same error. It appeared when I started my C# project on Win2008 64 (previos OS was Win2003 32). Also I found out that it worked fine in console apps and gave different errors in winforms. It seems that problem comes from the specifics of 32 ODBC driver working on 64-bit systems. My solution was:
我有同样的错误。它出现在我在 Win2008 64(以前的操作系统是 Win2003 32)上启动我的 C# 项目时。我还发现它在控制台应用程序中运行良好,并在 winforms 中出现了不同的错误。问题似乎来自在 64 位系统上工作的 32 ODBC 驱动程序的细节。我的解决方案是:
// Program.cs
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// it is important to open paradox connection before creating
// the first form in the project
if (!Data.OpenParadoxDatabase())
return;
Application.Run(new MainForm());
}
The connectionstring is common:
连接字符串很常见:
string connStr = @"Driver={{Microsoft Paradox Driver (*.db )}};DriverID=538;
Fil=Paradox 7.X;DefaultDir=C:\DB;Dbq=C:\DB;
CollatingSequence=ASCII;";
After opening connection you may close it in any place after creating first Form (if you need to keep DB closed most of time), for example:
打开连接后,您可以在创建第一个表单后的任何地方关闭它(如果您需要大部分时间保持数据库关闭),例如:
private void MainForm_Load(object sender, EventArgs e)
{
Data.CloseParadoxDatabase();
}
After doing that you may open and close connection every time you want during execution of your application and you willn't get any exceptions.
这样做之后,您可以在应用程序执行期间每次打开和关闭连接,并且不会出现任何异常。