ADODATASET中应把ID字段的AutoGenerateValue设为arAutoInc就可以了
(双击鼠标编辑ADODATASET的字段信息,选择添加所有字段的菜单项后,选择ID字段,
把它的AutoGenerateValue设为arAutoInc就可以字段获取自动增加的主表的ID号
)
再不清楚可看该属性(TField.AutoGenerateValue)的帮助信息
Indicates whether the field values can be generated by the server rather than entered by the user.
property AutoGenerateValue: TAutoRefreshFlag;
Description
Use AutoGenerateValue to indicate when field values can be generated by the database. Such fields include autoincrement fields and fields with default values.
By default, values inserted automatically into such fields when a record is posted are not automatically refetched by the dataset. Instead, the application must call the dataset抯 Refresh method to update the field component抯 Value property. These values can be automatically updated if the dataset抯 AutoRefresh property is True. However, some database drivers can抰 determine which fields can have values supplied automatically by the server. For these cases, applications can provide this information by setting the AutoGenerateValue property. Use this property to indicate whether the field is an autoincrement field (arAutoInc), a field with a default value (arDefault), or a field whose value is not automatically generated (arNone).
AutoGenerateValue is not always required. Fields with an AutoGenerateValue property of arNone may still be updated if the driver supplies metadata that indicates it has a default value or an autoincrement value. However, it is good practice to supply this information because not all drivers supply this metadata.
Note: Trying to change the AutoGenerateValue property when the field抯 dataset is open generates an exception. Thus, AutoGenerateValue only works with persistent field components, which remain when the dataset is closed.
Note: If the field is not in a BDE-enabled dataset or if the dataset抯 AutoRefresh property is False, this property has no effect.