title: How to bind Observable Collection and Save to Database
body: <p>I will be doing an MVVM Project soon and I'm working a couple tutorial/examples out. How do I take the following code and connect it to a database. If I were to have a datagrid, how can I change information in the datagrid and have it automatically update? I'll be using MS SQL. Thanks for any tips or advice.</p>
  
  <pre><code>Class Person 
  
    Property _name As Integer
  Property Name As Integer
      Get
          Return _name
      End Get
      Set(value As Integer)
          _name = value
          RaisePropertyChanged("Name")
  
      End Set
  End Property
  End class
  </code></pre>
  
  <hr>
  
  <p>Then in another class:</p>
  
  <pre><code>Class Collections
  
  Public namelist As New ObservableCollection(Of Person)
  
      namelist.Add(New Person With {.Name = Nothing}) 
  </code></pre>
  
  <p>--- Then in XAML</p>
  
  <pre><code>    &lt;ObjectDataProvider x:Key="test" ObjectType="{x:Type local:Collections}"
  
       &lt;DataGrid ItemsSource="{Binding Source= {StaticResource test}}"&gt;
  
        &lt;DataGridTextColumn Header="Name" Binding="{Binding Sample, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /&gt;
  
    ect...ect....ect...
  </code></pre>
  
  <p>Now where or how do I connect my MS SQL table to all this?</p>