CONECTAR DATAGRID AO BANCO DE DADOS ACCESS
Alterado em 03/03/2024 13:39:00
Public conex As ADODB.Connection
Public rs As New ADODB.Recordset
Set conex = New ADODB.Connection
With conex
.Provider = "Microsoft.JET.OLEDB.4.0"
.ConnectionString = (App.Path + "\" + "id.mdb")
'.Mode = adModeShareExclusive
.Open
End With
rs.Open "Select * from tblingre order by ingrediente", conex, adOpenKeyset, adLockOptimistic
CarregaDados
'Inicia o grid
iniciagrid
'rotina utilizada para iniciar o grid
Private Sub iniciagrid()
Dim sql As String
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient ' Isto preencher seu Datagrid, éo Cursor.
'inicializar o recordset que será utilizado para alimentar o grid
sql = "select * from tblingre"
'rs.Open sql, com, adOpenDynamic, adLockOptimistic
'Habilitar as operações de insert, delete e update
DataGrid1.AllowAddNew = True
DataGrid1.AllowUpdate = True
DataGrid1.AllowDelete = True
'Colocar o recordset como fonte de dados do grid
Set DataGrid1.DataSource = rs
'Atualiar o recordset
DataGrid1.Refresh
'ajustar a largura das colunas
DataGrid1.Columns(0).Width = 3300
DataGrid1.Columns(1).Width = 1150
'DataGrid1.Columns(2).Width = 1350
'DataGrid1.Columns(3).Width = 700
' DataGrid1.Columns(4).Width = 1100
End Sub
Faça seu login para responder