public static TableTown ZnajdzMiasto(string id) { TableTown miasto = tableTown.Select(n => n).Where(x => x.GetId() == id).FirstOrDefault(); return(miasto); }
//Update tables internal void UpdateTown(TableTown Town) { SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); } catch (SqlException se) { return; } SqlCommand cmd = new SqlCommand("Update Town" + " Set Name = @Name, Population = @Population, IdLoc = @IdLoc, Military = @Military, Prosperity = @Prosperity, Food = @Food where IdTown = @IdTown", conn); SqlParameter param = new SqlParameter(); param.ParameterName = "@Name"; param.Value = Town.GetName(); param.SqlDbType = SqlDbType.VarChar; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Population"; param.Value = Town.GetPopulation(); param.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@IdLoc"; param.Value = Town.GetIdLoc(); param.SqlDbType = SqlDbType.VarChar; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Military"; param.Value = Town.GetMilitary(); param.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Prosperity"; param.Value = Town.GetProsperity(); param.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@Food"; param.Value = Town.GetFood(); param.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(param); param = new SqlParameter(); param.ParameterName = "@IdTown"; param.Value = Town.GetId(); param.SqlDbType = SqlDbType.VarChar; cmd.Parameters.Add(param); try { cmd.ExecuteNonQuery(); } catch (SqlException se) { return; } conn.Close(); conn.Dispose(); }