C# 在C中读取SQLite数据库作为文件#
关于如何读取NexusOne中的SQLite数据库并使用C#.Net将其读取到PC上,我脑子里有一点小问题 在我的android应用程序的初始加载中,数据库将从Asset复制到C# 在C中读取SQLite数据库作为文件#,c#,android,sqlite,filestream,outputstream,C#,Android,Sqlite,Filestream,Outputstream,关于如何读取NexusOne中的SQLite数据库并使用C#.Net将其读取到PC上,我脑子里有一点小问题 在我的android应用程序的初始加载中,数据库将从Asset复制到/data/data/com.example.myapp/databases作为OutputStream。这是代码 //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB
/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=newsqliteconnection(“数据源=MyDB.db”)
中放置断点时,connection.DataBase
始终等于“main”。数据库名称应为“MyDB”而不是“main”。我的sqlite数据库文件似乎无法读取,可能是因为它是使用Stream
创建的,或者可能是因为它不是数据库文件?因为当我检查文件类型时,它显示的是“文件”而不是“数据库文件”
任何人都知道如何使用C#读取sqlite数据库文件。我想到的第一件事是使用
FileStream
和StreamReader
/StreamWriter
。但是我不知道如何开始。使用类似的工具,以确保查看数据库中表的名称,甚至可以打开数据库。一旦您获得了这些信息,您应该能够使用SQLiteConnection对象打开数据库。谢谢您的回复。我正在使用SQLite数据库浏览器浏览我的数据,我知道表就在那里。@klaydze在某个网站上抛出你的表,我来看看。