0
votes

I am trying to build an Android Xamarin Application. I have created an SQLite database named regjistri.sqlite . The database it's not corrupted, I can open it via SQLite browser on my PC. This database I have save it to my android Documents folder. I am trying to access it like below via sqlite-net-pcl library.

string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "regjistri.sqlite");
var db = new SQLiteConnection(dbPath);
var data = db.Query<object>("SELECT COUNT(*) FROM tblLidhja ");

Also I have gice the application the reading and writing permissions. When I debug it via USB cable, it give me the "SQLite.SQLiteException: no such table: tblLidhja" exception. Can someone help me whats may be wrong, or what should I change to read some data?

1
You mean instead of var data = db.Query<object>("SELECT COUNT() FROM tblLidhja "); it should be var data = db.Query<tblLidhja>("SELECT COUNT() FROM tblLidhja "); ? - Adnand
What is your actual tblLidhja class code and where is the TableCreate call in your code? - SushiHangover
if the path does not exist SQLite will create an empty db for you - this is what I suspect is happening - your path is not correct. Use File.Exists to verify - Jason
You have to call db.CreateTable<tblLidhja>() after the connection to DB is opened and before querying any data from it (that's what the exception is telling you - there is no such table in your DB). You can find an example at sqlite-net repo page: github.com/praeclarum/sqlite-net - Vitalii Ilchenko

1 Answers

0
votes

Before getting data , first need to check whether this table is exist in data base .You can refer to this document to check .

By the way ,having a try with this way to get count from database:

var db = new SQLiteConnection("DbPath");
var stocksStartingWithA = db.Query<TableName>("SELECT * FROM DbNmae ");
int count = stocksStartingWithA.Count; //get count from table

Here is similar discussion with java code, but it also can be refer in xamrin project.