private ItemType ItemTypeSelect(string commandText) { try { using (sqLiteConnection) { sqLiteConnection.Open(); SQLiteCommand mycommand = new SQLiteCommand(sqLiteConnection) {CommandText = commandText}; SQLiteDataReader reader = mycommand.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) { int id = reader.GetInt32(0); string name = reader.GetString(1); string description = reader.GetValue(2).ToString(); ItemType itemType = new ItemType { Id = id, Name = name, Description = description, }; Log.Debug("Found ItemType: {0}", itemType.Format()); return itemType; } reader.Close(); sqLiteConnection.Close(); } } catch (Exception exception) { Log.Error(exception.ToString()); } return null; }
public int ItemTypeUpdate(ItemType itemType) { try { string commandText = @"UPDATE ItemType SET Name = @name, Description = @description WHERE Id = " + itemType.Id; Log.Debug("ItemTypeUpdate: [{0}], ItemType={1}", commandText, itemType.Format()); using (sqLiteConnection) { using (SQLiteCommand sqLiteCommand = new SQLiteCommand(commandText, sqLiteConnection)) { sqLiteConnection.Open(); sqLiteCommand.Parameters.AddWithValue("@name", itemType.Name); sqLiteCommand.Parameters.AddWithValue("@description", itemType.Description); int rowsUpdated = sqLiteCommand.ExecuteNonQuery(); sqLiteConnection.Close(); return rowsUpdated; } } } catch (Exception exception) { Log.Error(exception.ToString); return 0; } }