Table of Contents

Class CommandBuilder

Namespace
Dynamicweb.Data
Assembly
Dynamicweb.Core.dll

The class represents a CommandBuilder to ease creation of parameterized SQL-queries.

public class CommandBuilder
Inheritance
CommandBuilder
Inherited Members

Examples

using System;

namespace Dynamicweb.Data.Examples
{
    class CommandBuilderSample
    {
        public int test()
        {
            var commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";

            var commandBuilder = new CommandBuilder();
            commandBuilder.Add(commandText, 1, 10);

            return Database.ExecuteNonQuery(commandBuilder);
        }

        public int test2()
        {
            CommandBuilder commandBuilder = new CommandBuilder();
            commandBuilder.Add("UPDATE EmailMarketingEmail SET EmailLastExportDate ={0} WHERE EmailId IN ({1})", DateTime.Now, "1, 13, 24");

            return Database.ExecuteNonQuery(commandBuilder);
        }
    }
}

Constructors

CommandBuilder()

Initializes a new instance of the CommandBuilder class.

public CommandBuilder()

Examples

using System;

namespace Dynamicweb.Data.Examples
{
    class CommandBuilderSample
    {
        public int test()
        {
            var commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";

            var commandBuilder = new CommandBuilder();
            commandBuilder.Add(commandText, 1, 10);

            return Database.ExecuteNonQuery(commandBuilder);
        }

        public int test2()
        {
            CommandBuilder commandBuilder = new CommandBuilder();
            commandBuilder.Add("UPDATE EmailMarketingEmail SET EmailLastExportDate ={0} WHERE EmailId IN ({1})", DateTime.Now, "1, 13, 24");

            return Database.ExecuteNonQuery(commandBuilder);
        }
    }
}

Methods

Add(CommandBuilder)

Adds the specified command builder to the instance.

public CommandBuilder Add(CommandBuilder commandBuilder)

Parameters

commandBuilder CommandBuilder

The command builder.

Returns

CommandBuilder

Examples

using System;

namespace Dynamicweb.Data.Examples
{
    class CommandBuilderSample
    {
        public int test()
        {
            var commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";

            var commandBuilder = new CommandBuilder();
            commandBuilder.Add(commandText, 1, 10);

            return Database.ExecuteNonQuery(commandBuilder);
        }

        public int test2()
        {
            CommandBuilder commandBuilder = new CommandBuilder();
            commandBuilder.Add("UPDATE EmailMarketingEmail SET EmailLastExportDate ={0} WHERE EmailId IN ({1})", DateTime.Now, "1, 13, 24");

            return Database.ExecuteNonQuery(commandBuilder);
        }
    }
}

Add(string, params object?[])

Adds the specified SQL expression with the specified values to the instance.

public CommandBuilder Add(string sqlExpression, params object?[] values)

Parameters

sqlExpression string

The expression.

values object[]

The values.

Returns

CommandBuilder

Examples

using System;

namespace Dynamicweb.Data.Examples
{
    class CommandBuilderSample
    {
        public int test()
        {
            var commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";

            var commandBuilder = new CommandBuilder();
            commandBuilder.Add(commandText, 1, 10);

            return Database.ExecuteNonQuery(commandBuilder);
        }

        public int test2()
        {
            CommandBuilder commandBuilder = new CommandBuilder();
            commandBuilder.Add("UPDATE EmailMarketingEmail SET EmailLastExportDate ={0} WHERE EmailId IN ({1})", DateTime.Now, "1, 13, 24");

            return Database.ExecuteNonQuery(commandBuilder);
        }
    }
}

Exceptions

ArgumentOutOfRangeException

parameters

Create(string, params object[])

Creates a new instance of the CommandBuilder class with the specified expression.

public static CommandBuilder Create(string expression, params object[] values)

Parameters

expression string

The expression.

values object[]

The values.

Returns

CommandBuilder

CommandBuilder containing the specified expression.

Examples

using System;

namespace Dynamicweb.Data.Examples
{
    class CommandBuilderSample
    {
        public int test()
        {
            var commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";

            var commandBuilder = new CommandBuilder();
            commandBuilder.Add(commandText, 1, 10);

            return Database.ExecuteNonQuery(commandBuilder);
        }

        public int test2()
        {
            CommandBuilder commandBuilder = new CommandBuilder();
            commandBuilder.Add("UPDATE EmailMarketingEmail SET EmailLastExportDate ={0} WHERE EmailId IN ({1})", DateTime.Now, "1, 13, 24");

            return Database.ExecuteNonQuery(commandBuilder);
        }
    }
}

CreateCommand(IDbConnection)

Creates a prepared command with command text and parameters using the specified connection.

public IDbCommand CreateCommand(IDbConnection connection)

Parameters

connection IDbConnection

The connection.

Returns

IDbCommand

Returns an IDbCommand instance.

CreateCommand(IDbConnection, IDbTransaction?)

Creates a prepared command with command text and parameters using the specified connection and transaction.

public IDbCommand CreateCommand(IDbConnection connection, IDbTransaction? transaction)

Parameters

connection IDbConnection

The connection.

transaction IDbTransaction

The transaction.

Returns

IDbCommand

An IDbCommand instance.

Exceptions

ArgumentNullException

connection

ToQueryText(IDataParameter, int)

Converts the IDataParameter to query text.

public static string ToQueryText(IDataParameter dataParameter, int parameterIndex)

Parameters

dataParameter IDataParameter

The data parameter.

parameterIndex int

Index of the parameter.

Returns

string

ToQueryText(IDbCommand?)

Converts the IDbCommand provider specific query text.

public static string ToQueryText(IDbCommand? command)

Parameters

command IDbCommand

The command.

Returns

string

ToQueryText(SqlCommand)

Converts the SqlCommand to query text.

public static string ToQueryText(SqlCommand command)

Parameters

command SqlCommand

The command.

Returns

string

ToQueryText(SqlParameter)

Converts the SqlParameter to query text.

public static string ToQueryText(SqlParameter parameter)

Parameters

parameter SqlParameter

The parameter.

Returns

string

ToQueryText(SqlParameter, int)

Converts the SqlParameter to query text.

public static string ToQueryText(SqlParameter parameter, int parameterIndex)

Parameters

parameter SqlParameter

The parameter.

parameterIndex int

Index of the parameter.

Returns

string

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

To top