I'm trying to adapt to VB.NET the code of the most voted answer from this post:
Sqlite Check if Table is Empty
Original code is
SQLiteDatabase db = table.getWritableDatabase();
String count = "SELECT count(*) FROM table";
Cursor mcursor = db.rawQuery(count, null);
mcursor.moveToFirst();
int icount = mcursor.getInt(0);
if(icount>0)
//leave
else
//populate table
My code looks like ('Only to have a message on the screen I will fill the If - Else code later')
Using conn As New SQLiteConnection("Data Source=myDataBase.sqlite;Version=3;foreign keys=true")
Try
conn.Open()
Dim emptyUserTable = "SELECT COUNT(*) FROM usersTable"
Dim cmdIsEmpty As SQLiteCommand = New SQLiteCommand(emptyUserTable, conn)
Try
Dim Answer As Integer
Answer = cmdIsEmpty.ExecuteNonQuery()
MsgBox(Answer)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Using
But the "Answer" is allways -1, with empty table or not.
I don´t know how to use getWritableDataBase because I get a getWritableDatabase is not a member of SQLiteConnection
The same with rawQuery.
How can I check if usersTable is empty or not on VB.NET?