public void SaveSoftware(SofwareItem softToSave) { SQLiteConnection conn = new SQLiteConnection("data source=itemsDatabase.db"); conn.Open(); using (SQLiteCommand com = new SQLiteCommand(conn)) { com.CommandText = "INSERT INTO Items (SerialNumber,ItemName,Price,LicenceKey,SizeInMB) " + "VALUES (" + softToSave.ItemID + ",'" + softToSave.ItemName + "','" + softToSave.ItemPrice + "'," + "'" + softToSave.LicenceKey + "','" + softToSave.SizeInMB + "')"; com.ExecuteNonQuery(); com.Dispose(); } conn.Close(); }
public void updateSoftware(int id, SofwareItem softToUpdate) { SQLiteConnection conn = new SQLiteConnection("data source=itemsDatabase.db"); conn.Open(); using (SQLiteCommand com = new SQLiteCommand(conn)) { com.CommandText = "UPDATE Items " + "SET ItemName='" + softToUpdate.ItemName + "', Price=" + softToUpdate.ItemPrice + ", LicenceKey=" + softToUpdate.LicenceKey + "," + " SizeInMB=" + softToUpdate.SizeInMB + " WHERE SerialNumber=" + id + ";"; com.ExecuteNonQuery(); com.Dispose(); } conn.Close(); }
public SofwareItem readSoftware(int id) { SofwareItem soft = new SofwareItem(); SQLiteConnection conn = new SQLiteConnection("data source=itemsDatabase.db"); conn.Open(); SQLiteCommand comm = new SQLiteCommand("SELECT LicenceKey,SizeInMB FROM Items WHERE ItemID=" + id + ";", conn); using (SQLiteDataReader read = comm.ExecuteReader()) { while (read.Read()) { soft.LicenceKey = read.GetString(0); soft.SizeInMB = read.GetInt32(1); } return(soft); } }