title: How to save changes from DataGridView to the database?
body: <p>I would like to save the changes made to a DataGridView into the database MS SQL CE,
  but i can't, the changes are not saved to the database....</p>
  
  <p>This the code (VB.net):</p>
  
  <pre><code>    Private Sub Form1_Load(ByVal sender As System.Object, 
          ByVal e As System.EventArgs) handles MyBase.Load
  
          Dim con As SqlCeConnection = New SqlCeConnection(@"Data  Source=C:\Users\utente\Documents\test.sdf")
  
          Dim cmd As SqlCeCommand = New SqlCeCommand("SELECT * FROM mytable", con)
  
          con.Open()
          myDA = New SqlCeDataAdapter(cmd)
          Dim builder As SqlCeCommandBuilder = New SqlCeCommandBuilder(myDA)
          myDataSet = New DataSet()
          myDA.Fill(myDataSet, "MyTable")
          DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView
          con.Close()
          con = Nothing
  
      End Sub
  
  
  
      Private Sub edit_rec()
  
          Dim txt1, txt2 As String
          Dim indice As Integer = DataGridView1.CurrentRow.Index
  
          txt1 = DataGridView1(0, indice).Value.ToString '(0 is the first column of datagridview)
          txt2 = DataGridView1(1, indice).Value.ToString '(1 is the second)        MsgBox(txt1 + "  " + txt2)
          '
          DataGridView1(0, indice).Value = "Pippo"
          DataGridView1(1, indice).Value = "Pluto"
          '
          Me.Validate()
          Me.myDA.Update(Me.myDataSet.Tables("MyTable"))
          Me.myDataSet.AcceptChanges()
          '
      End Sub
  </code></pre>
  
  <p>Thank you for any suggestion.  </p>