Class CommandBuilder
- Namespace
- Dynamicweb.Data
- Assembly
- Dynamicweb.Data.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
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()
Creates a prepared command with command text and parameters.
[Obsolete("Use CreateCommand(IDbConnection) instead. This method contains a memory leak.")]
public IDbCommand CreateCommand()
Returns
- IDbCommand
- Returns an IDbCommand instance.
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
ToQueryText(IDbCommand)
Converts the IDbCommand provider specific query text.
public static string ToQueryText(IDbCommand command)
Parameters
command
IDbCommand- The command.
Returns
ToQueryText(SqlCommand)
Converts the SqlCommand to query text.
public static string ToQueryText(SqlCommand command)
Parameters
command
SqlCommand- The command.
Returns
ToQueryText(SqlParameter)
Converts the SqlParameter to query text.
public static string ToQueryText(SqlParameter parameter)
Parameters
parameter
SqlParameter- The parameter.
Returns
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
ToString()
Returns a string that represents this instance.
public override string ToString()