请问如何在DAO编程访问Access数据库中自动查询到主表的子表。
'----------------- Type 类别 --------------------------------------------
dbTblTypeGroup = dbDatabase.CreateTableDef("Type")
With dbTblTypeGroup
dbFieldTypeGroup.dbFieldGoodsTypeIndex = .CreateField("TypeNameKey", dao.DataTypeEnum.dbLong)
dbFieldTypeGroup.dbFieldGoodsTypeIndex.Attributes = dbFieldTypeGroup.dbFieldGoodsTypeIndex.Attributes + dao.FieldAttributeEnum.dbAutoIncrField
dbFieldTypeGroup.dbFieldGoodsType_Bianma = .CreateField("Bianma", dao.DataTypeEnum.dbText, 25)
dbFieldTypeGroup.dbFieldGoodsType_Leibie = .CreateField("Leibie", dao.DataTypeEnum.dbText, 25)
End With
With dbTblTypeGroup.Fields
.Append(dbFieldTypeGroup.dbFieldGoodsTypeIndex)
.Append(dbFieldTypeGroup.dbFieldGoodsType_Bianma)
.Append(dbFieldTypeGroup.dbFieldGoodsType_Leibie)
End With
idx = dbTblTypeGroup.CreateIndex("TypeNameKey")
fldIndex = idx.CreateField("TypeNameKey", dao.DataTypeEnum.dbLong)
idx.Fields.Append(fldIndex)
idx.Primary = True
dbTblTypeGroup.Indexes.Append(idx)
dbDatabase.TableDefs.Append(dbTblTypeGroup)
dbDatabase.TableDefs.Refresh()
'----------------- Name 名称 ------------------------------------------------------------
dbTblNameGroup = dbDatabase.CreateTableDef("Name")
With dbTblNameGroup
dbFieldNameGroup.dbFieldGoodsTypeNameKey = .CreateField("TypeNameKey", dao.DataTypeEnum.dbLong)
dbFieldNameGroup.dbFieldGoodsNameIndex = .CreateField("NameSpecKey", dao.DataTypeEnum.dbLong)
dbFieldNameGroup.dbFieldGoodsNameIndex.Attributes = dbFieldNameGroup.dbFieldGoodsNameIndex.Attributes + dao.FieldAttributeEnum.dbAutoIncrField
dbFieldNameGroup.dbFieldGooddsName_Bianma = .CreateField("Bianma", dao.DataTypeEnum.dbText, 25)
dbFieldNameGroup.dbFieldGoodsName_Mingcheng = .CreateField("Mingcheng", dao.DataTypeEnum.dbText, 25)
End With
With dbTblNameGroup.Fields
.Append(dbFieldNameGroup.dbFieldGoodsTypeNameKey)
.Append(dbFieldNameGroup.dbFieldGoodsNameIndex)
.Append(dbFieldNameGroup.dbFieldGooddsName_Bianma)
.Append(dbFieldNameGroup.dbFieldGoodsName_Mingcheng)
End With
idx = dbTblNameGroup.CreateIndex("NameSpecKey")
fldIndex = idx.CreateField("NameSpecKey", dao.DataTypeEnum.dbLong)
idx.Fields.Append(fldIndex)
idx.Primary = True
dbTblNameGroup.Indexes.Append(idx)
dbDatabase.TableDefs.Append(dbTblNameGroup)
dbDatabase.TableDefs.Refresh()
relNew = dbDatabase.CreateRelation("TypeToName", dbTblTypeGroup.Name, dbTblNameGroup.Name, dao.RelationAttributeEnum.dbRelationUpdateCascade)
relNew.Fields.Append(relNew.CreateField("TypeNameKey"))
relNew.Fields("TypeNameKey").ForeignName = "TypeNameKey"
dbDatabase.Relations.Append(relNew)
代码如上。现在我想通过 TypeNameKey 值自动查询到Type表的一个关系子表的内容。能不能像ADO中一样使用child*什么的直接得到子表内容。
还有DAO中的relation定义后是如何使用的,我刚学这,不是很清除。赶紧现在我虽然定义了但是没有用到,每次我都是通过SQL层层查询到的结果。
希望各位大侠解惑。