CDaoTableDef::SetValidationRule

void SetValidationRule( LPCTSTR lpszValidationRule );
throw( CDaoException, CMemoryException );

Parameters

lpszValidationRule

A pointer to a string expression that validates an operation.

Remarks

Call this member function to set a validation rule for a tabledef. Validation rules are used in connection with update operations. If a tabledef contains a validation rule, updates to that tabledef must match predetermined criteria before the data is changed. If the change does not match the criteria, an exception containing the text of GetValidationText is displayed.

Validation is supported only for databases that use the Microsoft Jet database engine. The expression cannot refer to user-defined functions, domain aggregate functions, SQL aggregate functions, or queries. A validation rule for a CDaoTableDef object can refer to multiple fields in that object.

For example, for fields named hire_date and termination_date, a validation rule might be:

CString strRule = _T(“termination_date>hire_date”);
MyRs.SetValidationRule(strRule);

For more information on tabledefs, see the articles DAO Tabledef and DAO Tabledef: Using Tabledefs in Visual C++ Programmer's Guide. For related information, see the topic "ValidationRule Property" in DAO Help.

CDaoTableDef OverviewClass MembersHierarchy Chart

See Also   CDaoTableDef::GetValidationText, CDaoTableDef::SetValidationText, CDaoTableDef::GetValidationRule