我在读我的NexusOne中的SQLite数据库并使用C#.Net将其读取到我的电脑时感到有点皱纹。将SQLite数据库读为C#文件#
在我的android应用程序的初始加载中,数据库将从资产复制到/data/data/com.example.myapp/databases
为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”而不是“主”。似乎我的sqlite数据库文件无法读取,也许是因为它是使用Stream
创建的,或者可能是因为它不是数据库文件?因为当我检查文件类型时,它会显示“文件”而不是“数据库文件”。
任何人都有关于如何使用C#读取sqlite数据库文件的想法。我首先想到的是使用FileStream
和StreamReader
/StreamWriter
。但我不知道如何开始。
感谢您的回复。我正在使用SQLite数据库浏览器浏览我的数据,我知道该表在那里。 – klaydze
@klaydze在某个网站上扔掉你的桌子,我会看看。 – AngryHacker