📄 frmprincipal.frm
字号:
VERSION 5.00
Begin VB.Form FrmPrincipal
BorderStyle = 3 'Fixed Dialog
Caption = "ADO Recordset In-Memory"
ClientHeight = 1845
ClientLeft = 45
ClientTop = 435
ClientWidth = 7155
Icon = "FrmPrincipal.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1845
ScaleWidth = 7155
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton CmdCargar
Caption = "Load..."
Height = 330
Left = 135
TabIndex = 1
Top = 45
Width = 1050
End
Begin VB.ListBox List1
Height = 1230
Left = 135
TabIndex = 0
Top = 450
Width = 6855
End
End
Attribute VB_Name = "FrmPrincipal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ------------------------------------------------
' www.geocities.com/olto22vb
' Oliver Toro
' --------------------SP--------------------------
' Ejemplo de creacion de un recordset en memoria,
' agregando campos y filas, es util para cargar
' datos unbound en un recordset y luego manejarlo
' como un objeto ADO recordset normal.
' --------------------EN--------------------------
' Example to create an in-memory ADODB.recordset,
' with adding fields and rows, is used to load
' unbound data in a recordset and after that
' you can manage it as an ADO recordset object.
' ------------------------------------------------
' Noviembre - 2002
' ------------------------------------------------
Option Explicit
Dim rs As ADODB.Recordset
Private Sub CmdCargar_Click()
Dim arrFields As Variant
Set rs = New ADODB.Recordset
'Grabar el array de nombre de campos del recordset
arrFields = Array("Codigo", "Apellidos", "Nombres", "Direccion", "Edad", "Estado")
'crear un recordset in-memory
With rs.Fields
.Append "Codigo", adVarChar, 20, adFldRowID
.Append "Apellidos", adVarChar, 100, adFldUpdatable + adFldIsNullable
.Append "Nombres", adVarChar, 100, adFldUpdatable + adFldIsNullable
.Append "Direccion", adVarChar, 100, adFldUpdatable + adFldIsNullable
.Append "Edad", adInteger, , adFldUpdatable
.Append "Estado", adInteger, , adFldUpdatable
End With
rs.Open , , adOpenStatic, adLockOptimistic
'Llenar el recordset y mover al primer registro
rs.AddNew arrFields, Array("A123", "Toro Recalde", "Oliver Hernando", "calle abc", 28, 1)
rs.AddNew arrFields, Array("B224", "Barahona Davila", "Hernan Xavier", "calle xyz", 35, 1)
rs.Update
rs.MoveFirst
List1.Clear
rs.MoveFirst
Do While Not rs.EOF
List1.AddItem rs!codigo & vbTab & rs!Apellidos & vbTab & rs!nombres & vbTab & rs!direccion & vbTab & rs!edad & vbTab & rs!estado
rs.MoveNext
Loop
Set rs = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set rs = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -