Class CommandBuilder
- Namespace
- Dynamicweb.Data
- Assembly
- Dynamicweb.Core.dll
The class represents a CommandBuilder to ease creation of parameterized SQL-queries.
- Inheritance
-
Command
Builder
- 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 Command
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.
Parameters
commandBuilder
CommandBuilder The 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.
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
- Argument
Out OfRange Exception parameters
Create(string, params object[])
Creates a new instance of the Command
Parameters
Returns
- Command
Builder Command
Builder 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.
Parameters
connection
IDbConnection The connection.
Returns
- IDb
Command Returns an IDb
Command instance.
CreateCommand(IDbConnection, IDbTransaction?)
Creates a prepared command with command text and parameters using the specified connection and transaction.
Parameters
connection
IDbConnection The connection.
transaction
IDbTransaction The transaction.
Returns
- IDb
Command An IDb
Command instance.
Exceptions
- Argument
Null Exception connection
ToQueryText(IDataParameter, int)
Converts the IDataParameter to query text.
Parameters
dataParameter
IDataParameter The data parameter.
parameterIndex
intIndex of the parameter.
Returns
ToQueryText(IDbCommand?)
Converts the IDbCommand provider specific query text.
Parameters
command
IDbCommand The command.
Returns
ToQueryText(SqlCommand)
Converts the SqlCommand to query text.
Parameters
command
SqlCommand The command.
Returns
ToQueryText(SqlParameter)
Converts the SqlParameter to query text.
Parameters
parameter
SqlParameter The parameter.
Returns
ToQueryText(SqlParameter, int)
Converts the SqlParameter to query text.
Parameters
parameter
SqlParameter The parameter.
parameterIndex
intIndex of the parameter.
Returns
ToString()
Returns a string that represents this instance.