SQLite net PCL - a simple choice

I am using SQLite from a Windows application, and now I am developing a portable application in Xamarin, so I am using the sqlite net pcl plugin and I am having big problems to understand how it works.

I have a table created with the following text:

public class Config { public string IP { get; set; } [SQLite.Net.Attributes.Default(true, "Client 2")] public string ID { get; set; } } 

and create a table:

 db.CreateTable<Model.Config>(); 

Problem: now I want to select a value in the ID column, and I do the following:

 List<string> hhid = db.Query<string>("select ID from Config",null); 

I get this exception: "Object reference not set to an instance of an object"

How can I make a simple choice to find this field?

Thanks for any feedback.

+7
c # sqlite portable-class-library xamarin
source share
1 answer

Hoping this will be useful to someone in my place ...

Between the brackets (<>) the table name is displayed:

 db.Query<TableName>("select * from ...."); 

Some examples that worked for me:

Simple choice:

 var list = db.Query<MyTableName>("select * from MyTableName"); 

Select with restrictions:

 var list = db.Query<MyTableName>("select * from MyTableName where lastname=? and firstname=?", lastnameValue, firstNameValue); 
+10
source share

All Articles