ParentCatalog 속성 예제(VB)
다음 코드에서는 카탈로그에 테이블을 추가하기 전에 ParentCatalog 속성을 사용하여 공급자별 속성에 액세스하는 방법을 보여 줍니다. 이 속성은 Microsoft Jet 데이터베이스에 AutoIncrement 필드를 만드는 AutoIncrement입니다.
' BeginCreateAutoIncrColumnVB
Sub Main()
On Error GoTo CreateAutoIncrColumnError
Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
Set cat.ActiveConnection = cnn
With tbl
.Name = "MyContacts"
Set .ParentCatalog = cat
' Create fields and append them to the new Table object.
.Columns.Append "ContactId", adInteger
' Make the ContactId column and auto incrementing column
.Columns("ContactId").Properties("AutoIncrement") = True
.Columns.Append "CustomerID", adVarWChar
.Columns.Append "FirstName", adVarWChar
.Columns.Append "LastName", adVarWChar
.Columns.Append "Phone", adVarWChar, 20
.Columns.Append "Notes", adLongVarWChar
End With
cat.Tables.Append tbl
Debug.Print "Table 'MyContacts' is added."
' Delete the table as this is a demonstration.
cat.Tables.Delete tbl.Name
Debug.Print "Table 'MyContacts' is delete."
'Clean up
cnn.Close
Set cat = Nothing
Set tbl = Nothing
Set cnn = Nothing
Exit Sub
CreateAutoIncrColumnError:
Set cat = Nothing
Set tbl = Nothing
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then cnn.Close
End If
Set cnn = Nothing
If Err <> 0 Then
MsgBox Err.Source & "-->" & Err.Description, , "Error"
End If
End Sub
' EndCreateAutoIncrColumnVB
참고 항목
Append 메서드(ADOX 열)
Append 메서드(ADOX 테이블)
카탈로그 개체(ADOX)
열 개체(ADOX)
Columns 컬렉션(ADOX)
Name 속성(ADOX)
ParentCatalog 속성(ADOX)
테이블 개체(ADOX)
Type 속성(열)(ADOX)