2

关于如何读取来自我的 NexusOne 的 SQLite 数据库并使用 C#.Net 将其读取到我的 PC 上,我的头脑中有些许皱纹。

在我的 android 应用程序的初始加载中,数据库将从 Asset 复制到/data/data/com.example.myapp/databasesas OutputStream。这是代码。

        //Open your local db as the input stream
    InputStream myInput = myContext.getAssets().open(DB_NAME);

    // Path to the just created empty db
    String outFileName = DB_PATH + DB_NAME;

    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer))>0) {
        myOutput.write(buffer, 0, length);
    }

    //Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();

我创建了一个 C# 程序来读取 SQLite 数据库,但是在使用它初始化连接System.Data.SQLite时总是抛出一个错误“没有这样的表错误”。

当我在 中放置断点时SQLiteConnection connection = new SQLiteConnection("Data Source=MyDB.db")connection.DataBase总是等于“ main ”。数据库名称应该是“MyDB”而不是“main”。似乎我的 sqlite 数据库文件无法读取可能是因为它是使用创建的,Stream或者可能是因为它不是数据库文件?因为当我检查文件类型时,它显示的是“文件”而不是“数据库文件”。

任何人都知道如何使用 C# 读取 sqlite 数据库文件。我想到的第一件事是使用FileStreamStreamReader/ StreamWriter。但我不知道如何开始。

4

1 回答 1

0

使用像SQLite Admin这样的工具来确定数据库中表的名称,或者即使它可以打开。然后,一旦您获得了这些信息,您应该能够使用 SQLiteConnection 对象打开数据库。

于 2012-12-18T06:31:40.190 回答