sqlite-net recording in a certain field (c#)
-
The project uses OBD SQLitea library is used to work with it. sqlite-net♪ The table shows:
id | tag | text
First field - autoincrement
id
the second is the text field filled, the third field is also text, empty.Target: in a given location (by appropriate location)
id
ortag
(d) Make a record of the fieldtext
♪Can this even be achieved by sqlite-net? Or do you still need to use requests? If that's the case, what's the request? PS: Here's the table class, method
AddData
just adds the tape to the end of the table in the field.text
♪public class data { [PrimaryKey, AutoIncrement] public int id { get; set; } public string tag { get; set; } public string text { get; set; }
public data AddData (string Text) { //string dbPath; //string dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "products.db"); //dbPath = @" data source=C:/data.db; synchronous=Off "; var Data = new data() { text = Text }; using (var db = new SQLiteConnection("C:/data")) { db.Insert(Data); } return (Data); } }
-
For example, try this option with the record. Let's say at 0 id we don't have records, and at 1 and above we have an update of the existing records. By analogy, you can do a method with additional conditions you need.
public int SaveItem (Data item) { using (var databaseConnection = new SQLiteConnection("C:/data")) { if (item.id > 0) { databaseConnection.Update(item); return item.id; } else { return databaseConnection.Insert(item); } } }