public void Add(MedicineModel.Medicine medicine) { using (var conn = new SqliteConnection(_sqliteConnectionStringBuilder.ConnectionString)) { conn.Open(); //create MEDICINES table var createTableCmd = conn.CreateCommand(); createTableCmd.CommandText = "Create Table IF NOT EXISTS MEDICINES(" + "Id TEXT PRIMARY KEY , " + "Name TEXT NOT NULL, " + "Brand TEXT NOT NULL, " + "Price REAL NOT NULL, " + "Quantity INTEGER NOT NULL, " + "Expiry TEXT NOT NULL, " + "Notes TEXT NOT NULL)"; createTableCmd.ExecuteNonQuery(); //insert into MEDICINES table var insertCmd = conn.CreateCommand(); insertCmd.CommandText = $"INSERT INTO MEDICINES(Id, Name, Brand, Price, Quantity, Expiry, Notes) " + $"VALUES('{medicine.Id}', '{medicine.Name}', '{medicine.Brand}', '{medicine.Price}', '{medicine.Quantity}', '{medicine.Expiry}', '{medicine.Notes}')"; insertCmd.ExecuteNonQuery(); } }
public void Update(MedicineModel.Medicine medicine) { using (var conn = new SqliteConnection(_sqliteConnectionStringBuilder.ConnectionString)) { conn.Open(); //update into MEDICINES table var updateCmd = conn.CreateCommand(); updateCmd.CommandText = $"UPDATE MEDICINES SET Id='{medicine.Id}', " + $"Name ='{medicine.Name}' , " + $"Brand ='{medicine.Brand}' , " + $"Price = '{medicine.Price}', " + $"Quantity= '{medicine.Quantity}', " + $"Expiry= , '{medicine.Expiry}'" + $"Notes= '{medicine.Notes}'" + $" WHERE Id = '{medicine.Id}'"; updateCmd.ExecuteNonQuery(); } }