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;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
commandBuilderCommandBuilderThe command builder.
Returns
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
Returns
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
Add<T>(string, IEnumerable<T>)
Adds the specified SQL expression with the specified value to the instance.
public CommandBuilder Add<T>(string sqlExpression, IEnumerable<T> value) where T : IConvertible
Parameters
sqlExpressionstringThe expression.
valueIEnumerable<T>The value.
Returns
Type Parameters
T
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
Add<T>(string, T?)
Adds the specified SQL expression with the specified values to the instance.
public CommandBuilder Add<T>(string sqlExpression, T? value) where T : IConvertible
Parameters
sqlExpressionstringThe expression.
valueTThe value.
Returns
Type Parameters
T
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
Returns
- CommandBuilder
CommandBuilder containing the specified expression.
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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
connectionIDbConnectionThe 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
connectionIDbConnectionThe connection.
transactionIDbTransactionThe transaction.
Returns
- IDbCommand
An IDbCommand instance.
Exceptions
- ArgumentNullException
connection
Create<T>(string, IEnumerable<T>)
Creates a new instance of the CommandBuilder class with the specified expression.
public static CommandBuilder Create<T>(string expression, IEnumerable<T> value) where T : IConvertible
Parameters
expressionstringThe expression.
valueIEnumerable<T>The value.
Returns
- CommandBuilder
CommandBuilder containing the specified expression.
Type Parameters
T
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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);
}
}
Create<T>(string, T?)
Creates a new instance of the CommandBuilder class with the specified expression.
public static CommandBuilder Create<T>(string expression, T? value) where T : IConvertible
Parameters
expressionstringThe expression.
valueTThe value.
Returns
- CommandBuilder
CommandBuilder containing the specified expression.
Type Parameters
T
Examples
using System;
namespace Dynamicweb.Data.Examples;
public static class CommandBuilderSample
{
public static int Test()
{
string commandText = "SELECT * FROM [Page] WHERE ( [PageId] = {1} ) AND ( [AreaId] = {0} )";
var commandBuilder = new CommandBuilder();
commandBuilder.Add(commandText, 1, 10);
return Database.ExecuteNonQuery(commandBuilder);
}
public static 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);
}
}
ToQueryText(IDataParameter, int)
Converts the IDataParameter to query text.
public static string ToQueryText(IDataParameter dataParameter, int parameterIndex)
Parameters
dataParameterIDataParameterThe data parameter.
parameterIndexintIndex of the parameter.
Returns
ToQueryText(IDbCommand?)
Converts the IDbCommand provider specific query text.
public static string ToQueryText(IDbCommand? command)
Parameters
commandIDbCommandThe command.
Returns
ToQueryText(SqlCommand)
Converts the SqlCommand to query text.
public static string ToQueryText(SqlCommand command)
Parameters
commandSqlCommandThe command.
Returns
ToQueryText(SqlParameter)
Converts the SqlParameter to query text.
public static string ToQueryText(SqlParameter parameter)
Parameters
parameterSqlParameterThe parameter.
Returns
ToQueryText(SqlParameter, int)
Converts the SqlParameter to query text.
public static string ToQueryText(SqlParameter parameter, int parameterIndex)
Parameters
parameterSqlParameterThe parameter.
parameterIndexintIndex of the parameter.
Returns
ToString()
Returns a string that represents this instance.
public override string ToString()