Show / Hide Table of Contents

    IDataStore.SetValidate(short column, string rule) Method

    .NET Standard 2.x

    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: DWNet.Data

    Assembly: DWNet.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 validation rule for the third column (specified by the column number).

    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 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 the third column: value must be larger than 0.
                datastore.SetValidate(2, "budget > 0");
    
                // Sets the value 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