public AddressModel GetAddress(int streetId, string name) { List<AddressModel> addresses = new List<AddressModel>(); string constr = WebConfigurationManager.ConnectionStrings["Address"].ConnectionString; SqlConnection con = new SqlConnection(constr); con.Open(); SqlCommand selectCommand = new SqlCommand( "SELECT " + Properties.Settings.Default.ColumnAddressX + ", " + Properties.Settings.Default.ColumnAddressY + " FROM " + Properties.Settings.Default.TableAddress + " WHERE " + Properties.Settings.Default.ColumnAddressName + "='" + name + "' AND " + Properties.Settings.Default.ColumnAddressStreetId + "=" + streetId, con); SqlDataReader reader = selectCommand.ExecuteReader(); while (reader.Read()) { AddressModel address = new AddressModel { X = Convert.ToDouble(reader.GetValue(0)), Y = Convert.ToDouble(reader.GetValue(1)), SRS = Properties.Settings.Default.AddressSRS }; addresses.Add(address); } reader.Close(); con.Close(); return addresses[0]; }
public AddressModel[] GetAddressesByStreetId(int streetId) { List<AddressModel> addresses = new List<AddressModel>(); string constr = WebConfigurationManager.ConnectionStrings["Address"].ConnectionString; SqlConnection con = new SqlConnection(constr); con.Open(); SqlCommand selectCommand = new SqlCommand( "SELECT " + //Properties.Settings.Default.ColumnAddressId + ", " + Properties.Settings.Default.ColumnAddressName + " FROM " + Properties.Settings.Default.TableAddress + " WHERE " + Properties.Settings.Default.ColumnAddressStreetId + "=" + streetId.ToString() + " ORDER BY " + Properties.Settings.Default.ColumnAddressOrder, con); SqlDataReader reader = selectCommand.ExecuteReader(); while (reader.Read()) { AddressModel address = new AddressModel { //AddressId = reader.GetInt32(0), Name = reader.GetString(0) }; addresses.Add(address); } reader.Close(); con.Close(); return addresses.ToArray(); }