Show / Hide Table of Contents

    IDataStore.SetValidate(short column, string rule) Method

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

    0.5.0-alpha

    1.0.1 (current)

    Sets the validation rule for a column (specified by the column number) in the DataStore. This validation rule will be checked when calling the Update or the Validate method.

    Namespace: PowerBuilder.Data

    Assembly: PowerBuilder.Data.dll

    Syntax

      public bool SetValidate(short column, string rule);
    

    Parameters

    column System.Short

    The zero-based column number for which you want to set the input validation rule.

    rule System.String

    A string whose value is the rule for validating the data.

    Returns

    System.Boolean

    Returns true if it succeeds.

    Examples

    The following code example sets the vailation rule for column 3 (specified by the column number).

    using PowerBuilder.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SetValidateExample
        {
            private SchoolContext _context;
    
            public SetValidateExample(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 for column 3: value must be larger than 0.
                datastore.SetValidate(2, "budget > 0");
    
                // Sets the vaue for budget in row 1 to -350000
                datastore.SetItem(0, "budget", -350000m);
    
                // If data passes validation, commit data to database;
                // otherwise, error occurs.
                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