Simplify the creation of an IDbCommand object by allowing a stored procedure and optional parameters to be provided

Namespace: CodeSmith.Engine
Assembly: CodeSmith.Engine (in CodeSmith.Engine.dll) Version: 6.0.0.0 (7.0.0.15127)

Syntax

C#
public virtual IDbCommand CreateCommand(
	string connectionString,
	string spName,
	params string[] sourceColumns
)
Visual Basic
Public Overridable Function CreateCommand ( 
	connectionString As String,
	spName As String,
	ParamArray sourceColumns As String()
) As IDbCommand

Parameters

connectionString
Type: System..::..String
A valid connection string for an IDbConnection
spName
Type: System..::..String
The name of the stored procedure
sourceColumns
Type: array<System..::..String>[]()[][]
An array of string to be assigned as the source columns of the stored procedure parameters

Return Value

Type: IDbCommand
A valid IDbCommand object

Examples

 Copy imageCopy
IDbCommand command = helper.CreateCommand(conn, "AddCustomer", "CustomerID", "CustomerName");

Exceptions

ExceptionCondition
System..::..ArgumentNullExceptionThrown if connectionString is null
System..::..InvalidOperationExceptionThrown if any of the IDataParameters.ParameterNames are null, or if the parameter count does not match the number of values supplied
System..::..ArgumentNullExceptionThrown if spName is null
System..::..ArgumentExceptionThrown if the parameter count does not match the number of values supplied

See Also