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
CommandBuilderThe command builder.
Returns
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
Returns
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
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
IDbConnectionThe 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
IDbConnectionThe connection.
transaction
IDbTransactionThe 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
IDataParameterThe data parameter.
parameterIndex
intIndex of the parameter.
Returns
ToQueryText(IDbCommand?)
Converts the IDbCommand provider specific query text.
public static string ToQueryText(IDbCommand? command)
Parameters
command
IDbCommandThe command.
Returns
ToQueryText(SqlCommand)
Converts the SqlCommand to query text.
public static string ToQueryText(SqlCommand command)
Parameters
command
SqlCommandThe command.
Returns
ToQueryText(SqlParameter)
Converts the SqlParameter to query text.
public static string ToQueryText(SqlParameter parameter)
Parameters
parameter
SqlParameterThe parameter.
Returns
ToQueryText(SqlParameter, int)
Converts the SqlParameter to query text.
public static string ToQueryText(SqlParameter parameter, int parameterIndex)
Parameters
parameter
SqlParameterThe parameter.
parameterIndex
intIndex of the parameter.
Returns
ToString()
Returns a string that represents this instance.
public override string ToString()