Visual Basic para Aplicaciones - codigo para actualizar base de datos en access

Life is soft - evento anual de software empresarial
   
Vista:
Imágen de perfil de Ignacio

codigo para actualizar base de datos en access

Publicado por Ignacio ignacio@pri.gases.co.cu (7 intervenciones) el 13/02/2015 03:22:20
Omar trate de comentar tu respuesta pero no me habria el vinculo, asi que te respondo por un nuevo tema, parte de mi codigo es este...y mi email es ignacio@pri.gases.co.cu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Public Class Form2
    Public bandera As Boolean = True
    'BindingSource  
    Private WithEvents bs As New BindingSource
    Dim StrConexion As String
    Dim StrComando As String
    Dim adapter As New OleDbDataAdapter
    Dim Cb As OleDbCommandBuilder
    Dim copia As New DataSet
 
    Private bEdit As Boolean
    Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
 
        If bEdit Then
            'preguntar si se desea guardar  
            If (MsgBox( _
                    "Guardar cambios ?", _
                     MsgBoxStyle.YesNo, _
                    "guardar")) = MsgBoxResult.Yes Then
 
                Actualizar(False)
            End If
        End If
    End Sub
    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim camino As String = System.AppDomain.CurrentDomain.BaseDirectory()
        Dim s As String = "SELECT * FROM " & Form1.vtabla
        Dim enlace As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & camino & "indicadorbd.mdb" & ";Persist Security Info=False"
        cargar_registros(s, enlace)
 
    End Sub
    Private Sub cargar_registros( _
 ByVal StrComando As String, _
 ByVal StrConexion As String)
        'conexion
        adapter = New OleDbDataAdapter(StrComando, StrConexion)
        Cb = New OleDbCommandBuilder(adapter)
 
        adapter.Fill(copia, Form1.vtabla)
        Me.DataGridView1.DataSource = copia.Tables(Form1.vtabla)
 
        'formateo de columnas
        Me.DataGridView1.Columns("Id").Visible = False
        Me.DataGridView1.Columns("PLAN").Visible = False
 
 
        If Form1.vtabla = "indicadores" Then
            Me.DataGridView1.Columns("ene").Visible = False
            Me.DataGridView1.Columns("feb").Visible = False
            Me.DataGridView1.Columns("mar").Visible = False
            Me.DataGridView1.Columns("abr").Visible = False
            Me.DataGridView1.Columns("may").Visible = False
            Me.DataGridView1.Columns("jun").Visible = False
            Me.DataGridView1.Columns("jul").Visible = False
            Me.DataGridView1.Columns("ago").Visible = False
            Me.DataGridView1.Columns("sep").Visible = False
            Me.DataGridView1.Columns("oct").Visible = False
            Me.DataGridView1.Columns("nov").Visible = False
            Me.DataGridView1.Columns("dic").Visible = False
            Me.DataGridView1.Columns("VARIACION").Visible = False
            Me.DataGridView1.Columns("acumulado").Visible = False
            Me.DataGridView1.Columns("balance").Visible = False
            Me.DataGridView1.Columns("cumplimiento").Visible = False
        End If
        DataGridView1.Columns("descripcion").Width = 600
        DataGridView1.Columns("plan").Width = 100
        DataGridView1.Columns("cuenta").Width = 100
        DataGridView1.Columns("subcuenta").Width = 100
        DataGridView1.Columns("sctrol1").Width = 100
        DataGridView1.Columns("sctrol2").Width = 100
 
        With DataGridView1.ColumnHeadersDefaultCellStyle
            .ForeColor = Color.White
            .Font = New Font(DataGridView1.Font, FontStyle.Bold)
        End With
 
        ' Enlazar el BindingSource con el datatable anterior  
        ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
        bs.DataSource = copia
 
        With DataGridView1
            .Refresh()
            ' coloca el registro arriba de todo  
            .FirstDisplayedScrollingRowIndex = bs.Position
        End With
 
        bEdit = False
 
    End Sub
    Private Sub Actualizar(Optional ByVal bCargar As Boolean = True)
        ' Actualizar y guardar cambios  
 
        If Not bs.DataSource Is Nothing Then
            adapter.Update(copia, Form1.vtabla)
        End If
    End Sub
 
    Private Sub DataGridView1_CellEndEdit( _
    ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
        Handles DataGridView1.CellEndEdit
        bEdit = True
    End Sub
 
    Private Sub btn_Update_Click_1(sender As System.Object, e As System.EventArgs) Handles btn_Update.Click
        Actualizar()
    End Sub
 
    Private Sub dataGridView1_RowsAdded(ByVal sender As Object, _
        ByVal e As DataGridViewRowsAddedEventArgs) _
        Handles DataGridView1.RowsAdded
 
    End Sub
 
 
End Class
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder