Value 속성 예제(VB)
이 예제에서는 Employees 테이블의 필드 및 속성 값을 표시하여 Field 및 Property 개체가 있는 Value 속성을 보여 줍니다.
'BeginValueVB
Public Sub Main()
On Error GoTo ErrorHandler
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
' connection and recordset variables
Dim rstEmployees As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Dim strSQLEmployees As String
' field property variables
Dim fld As ADODB.Field
Dim prp As ADODB.Property
' Open connection
Set Cnxn = New ADODB.Connection
strCnxn = "Provider='sqloledb';Data Source='MySqlServer';" & _
"Initial Catalog='Pubs';Integrated Security='SSPI';"
Cnxn.Open strCnxn
' Open recordset with data from Employees table
Set rstEmployees = New ADODB.Recordset
strSQLEmployees = "employee"
rstEmployees.Open strSQLEmployees, Cnxn, , , adCmdTable
'rstEmployees.Open strSQLEmployees, Cnxn, adOpenStatic, adLockReadOnly, adCmdTable
' the above two lines of code are identical
Debug.Print "Field values in rstEmployees"
' Enumerate the Fields collection of the Employees table
For Each fld In rstEmployees.Fields
' Because Value is the default property of a
' Field object, the use of the actual keyword
' here is optional.
Debug.Print " " & fld.Name & " = " & fld.Value
Next fld
Debug.Print "Property values in rstEmployees"
' Enumerate the Properties collection of the Recordset object
For Each prp In rstEmployees.Properties
Debug.Print " " & prp.Name & " = " & prp.Value
' because Value is the default property of a Property object
' use of the actual Value keyword is optional
Next prp
' clean up
rstEmployees.Close
Cnxn.Close
Set rstEmployees = Nothing
Set Cnxn = Nothing
Exit Sub
ErrorHandler:
' clean up
If Not rstEmployees Is Nothing Then
If rstEmployees.State = adStateOpen Then rstEmployees.Close
End If
Set rstEmployees = Nothing
If Not Cnxn Is Nothing Then
If Cnxn.State = adStateOpen Then Cnxn.Close
End If
Set Cnxn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
'EndValueVB
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기