在C#中读取.db文件

Co *_*der 5 .net c# database paradox

 string Path = @"c:\Database\Mydatabase.db";

     string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Paradox 5.x;";

    // Define the database query    
    string mySelectQuery = "SELECT id,name FROM people WHERE id < 3;";

    // Create a database connection object using the connection string    
    OleDbConnection myConnection = new OleDbConnection(myConnectionString);

    // Create a database command on the connection using query    
    OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

    // Open the connection    
    myCommand.Connection.Open();

    // Create a database reader    
    OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
Run Code Online (Sandbox Code Playgroud)

错误发生在myCommand.Connection.Open(); 它说:'c:\ Database\Mydatabase.db'不是有效的路径.确保路径名拼写正确,并且您已连接到文件所在的服务器.

我试图在C#中读取.db文件.但是,我收到一个错误,我确信文件位于那里,错误对我来说没有意义.请你帮助我好吗 ?或者如何在C#中读取.db(paradox)数据库文件?

编辑: string Path = @"c:\ Database \";

此案例的错误是"Microsoft Jet数据库引擎无法找到对象'人'.请确保该对象存在,并且您正确拼写其名称和路径名."

如果我改变它,C#如何找到将要使用的数据库文件?因为,我没有在任何地方指定文件名"Mydatabase.db"

在此输入图像描述

tca*_*vin 2

确认它是一个 SQLite 数据库,我刚刚将其下载到手机上并使用 SQLite 查看器查看。


您需要下载 SQLite 的 ADO.NET 提供程序:

“官方”版本(来自 SQLite,而不是 MS)

http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

旧版本

http://sqlite.phxsoftware.com/