Show / Hide Table of Contents

    IDataStore.SetValidate(string column, string rule) Method

    .NET Standard 2.x

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

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public bool SetValidate(string column, string rule);
    

    Parameters

    column System.String

    The column name 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 validation rule for the budget column (specified by the column name).

    using DWNet.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataStoreExamples
    {
        public class SetValidateExample
        {
            private readonly SchoolContext _context;
    
            public SetValidateExample(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 for the budget column: value must be larger 
                // than 0.
                datastore.SetValidate("budget", "budget > 0");
    
                // Sets the vaue for budget in the first row 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!
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon