Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/05/2010, 02:00
Avatar de Sergio18
Sergio18
 
Fecha de Ingreso: abril-2010
Ubicación: No quieras saberlo
Mensajes: 94
Antigüedad: 15 años
Puntos: 0
Editar Datagridview

Hola, os cuento:

Tengo 3 clases :
En una tengo la conexion a la base de datos (Access)

Código vb:
Ver original
  1. Public Class ClsBaseAccess
  2.  
  3. Protected _cnClientes As OleDb.OleDbConnection
  4.  
  5. Public Sub New()
  6.  
  7. _cnClientes = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=C:\SergioNet\Agenda 2010\Agenda.mdb")
  8.  
  9. End Sub
  10.  
  11. End Class


En otra la sentencia SQL:

Código vb:
Ver original
  1. Public Class ClsSentencias
  2. Inherits ClsBaseAccess
  3.  
  4. Public Function EditarClientes() As OleDb.OleDbDataAdapter
  5.  
  6. Dim CEditar As New OleDb.OleDbDataAdapter
  7.  
  8. '("update tbl_clientes set nombre='" & "', apellidos='" & _
  9. ' "',direccion='" & "',provincia='" & "',ciudad='" & _
  10. ' "',telefono='" & "',cp='" & "',where idcliente = " & "", _cnClientes)
  11.  
  12. Return CEditar
  13.  
  14. End Function
  15.  
  16. End Class

Y en otra tengo el dataset:

Código vb:
Ver original
  1. Public Class ClsTablas
  2. Public Function EditarTablaClientes() As DataSet
  3.  
  4. Dim ds As New DataSet
  5. Dim da As New ClsSentencias
  6.  
  7. da.EditarClientes.Update(ds)
  8.  
  9. Return ds
  10.  
  11. End Function
  12.  
  13. End Class

Despues en el form1 es cuando quiero editar el Grid:

Código vb:
Ver original
  1. Private Sub BtEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtEditar.Click
  2.  
  3. Dim ds As New ClsTablas
  4.  
  5. Grid1.DataSource = ds.EditarTablaClientes.Tables(0)
  6.  
  7. End Sub

Tambien agrego los datos del datagridview al formulario

Código vb:
Ver original
  1. Me.txtId.Text = Me.Grid1.Rows(e.RowIndex).Cells(0).Value()
  2. Me.txtNombre.Text = Me.Grid1.Rows(e.RowIndex).Cells(1).Value()
  3. Me.txtApellidos.Text = Me.Grid1.Rows(e.RowIndex).Cells(2).Value()
  4. Me.txtDireccion.Text = Me.Grid1.Rows(e.RowIndex).Cells(3).Value()
  5. Me.CbProvincia.Text = Me.Grid1.Rows(e.RowIndex).Cells(4).Value()
  6. Me.CbCiudad.Text = Me.Grid1.Rows(e.RowIndex).Cells(5).Value()
  7. Me.txtTelefono.Text = Me.Grid1.Rows(e.RowIndex).Cells(6).Value()
  8. Me.txtCodigoPostal.Text = Me.Grid1.Rows(e.RowIndex).Cells(7).Value()

Lo que quiero que haga es cuando yo cargue los datos del datagrid al formulario, cuando edite en un textbox y le de al boton editar este se edite y guarde en la base de datos y el datagrid

Saludos