2012-12-18 55 views
2

我在读我的NexusOne中的SQLite数据库并使用C#.Net将其读取到我的电脑时感到有点皱纹。将SQLite数据库读为C#文件#

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

 //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”而不是“主”。似乎我的sqlite数据库文件无法读取,也许是因为它是使用Stream创建的,或者可能是因为它不是数据库文件?因为当我检查文件类型时,它会显示“文件”而不是“数据库文件”。

任何人都有关于如何使用C#读取sqlite数据库文件的想法。我首先想到的是使用FileStreamStreamReader/StreamWriter。但我不知道如何开始。

回答

0

使用像SQLite Admin这样的工具来查看数据库中表格的名称,或者即使可以打开它。然后一旦你有了这些信息,你应该可以用SQLiteConnection对象打开数据库。

+0

感谢您的回复。我正在使用SQLite数据库浏览器浏览我的数据,我知道该表在那里。 – klaydze

+0

@klaydze在某个网站上扔掉你的桌子,我会看看。 – AngryHacker