Show / Hide Table of Contents

    IDataStore.Validate() Method

    .NET Standard 2.x | Current Version (1.0.1)

    0.5.0-alpha 1.0.1 (current)

    Verifies the data using the data validation rules set in the DataStore.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public bool Validation();
    

    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 return false if any data 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 Example1()
            {
                // 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(2, "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.
                if (datastore.Validate())
                {
                    datastore.Update();
                }
                else
                {
                    Console.WriteLine("Invalid data! Please check!");
                }
    
                /*This code produces the following output:
                
                Invalid data! Please check!
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon