IDataStore.Validate(Out List<ValidationResult> validationResults) Method
.NET Standard 2.x | Current Version (1.0.1) 
Verifies the data using the data validation rules set in the DataStore, and outputs the verification results.
Namespace: PowerBuilder.Data
Assembly: PowerBuilder.Data.dll
Syntax
public bool Validation(out List<ValidationResult> validationResults);
Parameters
validationResults System.Collections.Generic.List<System.ComponentModel.DataAnnotations.ValidationResult>
A list of validation results.
Returns
System.Boolean
Returns true if all data meet the validation rule; false if any data does not meet the validation rule.
Examples
The following code example specifies the validation rule (budget is greater than 0), and then modifies one of the budget values to a negative value. The Validate method will display the error message for the data that does not meet the rule.
using PowerBuilder.Data;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class ValidateExample
{
private SchoolContext _context;
public ValidateExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
// Retrieves rows from the database for datastore.
datastore.Retrieve();
// Sets the validation rule with column 3: value for budget must be
// greater than 0.
datastore.SetValidate("budget", "budget > 0");
// Sets the vaue for budget in row 1 to -350000.
datastore.SetItem(0, "budget", -350000m);
// If all data passes validation, commit data to database,
// otherwise, display an error.
bool valid = datastore.Validate(out List<ValidationResult> results);
if (valid)
{
datastore.Update();
}
else
{
foreach (var validationResult in results)
{
Console.WriteLine("Error Message: {0}",
validationResult.ErrorMessage);
}
}
/*This code produces the following output:
Error Message: Row 0 column Budget data validation failed.
*/
}
}
}
Applies to
.NET Standard
2.x