Código:
Imports System.Data Imports System.Data.SqlClient Public Class frmSucursales Public Sub frmSucursales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim cadCon As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BANCOLOMBIA.mdf;Integrated Security=True;User Instance=True" Dim dsSucursal As New DataSet Dim daSucural As New SqlDataAdapter("SELECT ID_SUCURSAL, NOMBRE_SUCURSAL, DIR_SUCURSAL, TEL_SUCURSAL FROM SUCURSALES", cadCon) Dim cbSucursales As New SqlCommandBuilder(daSucural) daSucural.Fill(dsSucursal, "Sucursales") Dim bsSucursales As New BindingSource(dsSucursal, "SUCURSALES") daSucural.InsertCommand = cbSucursales.GetInsertCommand daSucural.UpdateCommand = cbSucursales.GetUpdateCommand daSucural.DeleteCommand = cbSucursales.GetDeleteCommand txt_idsucursal.DataBindings.Add("Text", bsSucursales, "ID_SUCURSAL", True) txt_nombre_sucursal.DataBindings.Add("Text", bsSucursales, "NOMBRE_SUCURSAL", True) txt_dir_sucursal.DataBindings.Add("Text", bsSucursales, "DIR_SUCURSAL", True) txt_tel_sucursal.DataBindings.Add("Text", bsSucursales, "TEL_SUCURSAL", True) DataGridView1.DataSource = bsSucursales SUCURSALESBindingNavigator.BindingSource = bsSucursales Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Public Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click End Sub Private Sub SUCURSALESBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SUCURSALESBindingNavigatorSaveItem.Click bsSucursales.EndEdit() End Sub Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try bsSucursales.AddNew() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub End Class