public class CountriesViewModel : INotifyPropertyChanged { static String connectionString = @"connstr"; SqlConnection con; SqlCommand cmd; SqlDataAdapter adapter; DataSet ds; public ObservableCollection Countries { get; set; } public String txtSelectedItem { get; set; } public CountriesViewModel() { txtSelectedItem = "Please select a country"; FillList(); } public void FillList() { try { con = new SqlConnection(connectionString); con.Open(); cmd = new SqlCommand("select * from [dbo].[Country]", con); adapter = new SqlDataAdapter(cmd); ds = new DataSet(); adapter.Fill(ds, "tblCountries"); if (Countries == null) Countries = new ObservableCollection(); foreach (DataRow dr in ds.Tables[0].Rows) { Countries.Add(new Country { CountryId = Convert.ToInt32(dr[0].ToString()), CountryName = dr[1].ToString(), }); } } catch (Exception ex) { } finally { ds = null; adapter.Dispose(); con.Close(); con.Dispose(); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }