public static List <Landlord> GetLandlords() { using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString())) { connection.Open(); List <Landlord> landlords = new List <Landlord>(); using (SQLiteCommand command = connection.CreateCommand()) { command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = "SELECT LandlordName FROM Landlord"; SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string name = (string)reader["LandlordName"]; Landlord landlord = new Landlord { Name = name }; landlords.Add(landlord); } } reader.Close(); } return(landlords); } }
public static void Save(Landlord landlord) { using (SQLiteConnection connection = new SQLiteConnection(LoadConnectionString())) { connection.Open(); using (SQLiteCommand command = connection.CreateCommand()) { command.Connection = connection; command.CommandType = CommandType.Text; command.CommandText = "INSERT INTO Landlord (LandlordName, Code) Values (@LandlordName, @Code)"; command.Parameters.AddWithValue("@LandlordName", landlord.Name); command.Parameters.AddWithValue("@Code", landlord.Code); command.ExecuteNonQuery(); } } }