Show / Hide Table of Contents

    ISqlWhereBuilder.Where(string left, ISqlParameter parameter) Method

    .NET Standard 2.x

    Creates a WHERE clause, and adds a search condition to the WHERE clause. Specifies a SQL expression on the left of the operator and a SQL parameter on the right of the operator. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlWhereAndOr Where(string left, ISqlParameter parameter);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    parameter SnapObjects.Data.ISqlParameter

    An ISqlParameter object which represents a SQL parameter on the right of the operator.

    It can be created by calling the SqlBuilder.Parameter method.

    Returns

    SnapObjects.Data.ISqlWhereAndOr

    Returns the ISqlWhereAndOr object which can be used to add more search conditions to the current WHERE clause.

    Examples

    The following code example uses the Where method to specify the column value to equal to an input parameter.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereBuilderExamples
    {
        public class WhereExample
        {
            private readonly SchoolContext _context;
    
            public WhereExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example3()
            {
    
                //  Declares SqlQueryBuilder.
                ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement.
                sqlQueryBuilder.Select("Title")
                                .From("Course")
                                .Where("CourseID", SqlBuilder.Parameter<int>("courid"));
    
                // Shows the SQL statement.
                Console.WriteLine("The SQL statement: \n{0}",
                                 sqlQueryBuilder.ToSqlString(_context));
    
                // Executes the SQL statement.
                int courid = 1050;
                var title = _context.SqlExecutor
                    .Scalar<string>(sqlQueryBuilder, courid);
    
                Console.WriteLine();
                Console.WriteLine("Title : {0}.", title);
    
                /*This code produces the following output:
    
                The SQL statement:
                SELECT
                 [Title]
                FROM [Course]
                WHERE ([CourseID] = @courid)
    
                Title : Chemistry. 
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon