Create a new project with a form (form1) and a datagrid (dgContacts). Paste the following (remembering to alter the sql and connection strings).
Any data changed when the form is closed will be detected and the command builder is used to save the changes. This only works on DataGrids based on single table not views mind. It may need some tweaking as I haven't tested this in a while but it should give you a good start!
Cheers
Andrew
________________
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Private Const SELECT_STRING As String = "insert SQL select statement here"
Private Const CONNECT_STRING As String = "insert connection string here"
Private m_DataSet As DataSet
' Load the data.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data_adapter As SqlDataAdapter
data_adapter = New SqlDataAdapter(SELECT_STRING, CONNECT_STRING)
data_adapter.TableMappings.Add("Table", "Contacts")
m_DataSet = New DataSet()
data_adapter.Fill(m_DataSet)
dgContacts.SetDataBinding(m_DataSet, "Contacts")
dgContacts.DataSource = m_DataSet.Tables("Contacts")
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If m_DataSet.HasChanges() Then
Dim data_adapter As SqlDataAdapter
Dim command_builder As SqlCommandBuilder
data_adapter = New SqlDataAdapter(SELECT_STRING, CONNECT_STRING)
data_adapter.TableMappings.Add("Table", "Contacts")
command_builder = New SqlCommandBuilder(data_adapter)
data_adapter.Update(m_DataSet)
End If
End Sub
End Class