public void ReadFromDB(SqlConnection connection) { string sQuery = "SELECT DISTINCT f32_ad AS city " + "FROM UserFields407 " + "WHERE f32_ad IS NOT NULL AND f32_ad > '' " + "ORDER BY f32_ad"; SqlCommand sqlSelect = new SqlCommand(sQuery, connection); bool connectionCloseOnExit = false; Clear(); if (connection.State != System.Data.ConnectionState.Open) { connectionCloseOnExit = true; connection.Open(); } SqlDataReader sqlReader = sqlSelect.ExecuteReader(); _bEmpty = false; while (sqlReader.Read()) { if (sqlReader["city"] == null || sqlReader["city"] == DBNull.Value) { continue; } CityRecord cr = new CityRecord(); cr.Name = sqlReader["city"].ToString().Trim(); _Records.Add(cr); } sqlReader.Close(); if (connectionCloseOnExit == true) { connection.Close(); } }
public void ReadFromDB(SqlConnection connection) { string sQuery = "SELECT DISTINCT f32_ad AS city " + "FROM UserFields407 " + "WHERE f32_ad IS NOT NULL AND f32_ad > '' " + "ORDER BY f32_ad"; SqlCommand sqlSelect = new SqlCommand(sQuery, connection); bool connectionCloseOnExit = false; Clear(); if (connection.State != System.Data.ConnectionState.Open) { connectionCloseOnExit = true; connection.Open(); } SqlDataReader sqlReader = sqlSelect.ExecuteReader(); _bEmpty = false; while (sqlReader.Read()) { if (sqlReader["city"] == null || sqlReader["city"] == DBNull.Value) continue; CityRecord cr = new CityRecord(); cr.Name = sqlReader["city"].ToString().Trim(); _Records.Add(cr); } sqlReader.Close(); if (connectionCloseOnExit == true) connection.Close(); }