本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Data.Database.AddParameter方法的典型用法代码示例。如果您正苦于以下问题:C# Database.AddParameter方法的具体用法?C# Database.AddParameter怎么用?C# Database.AddParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.EnterpriseLibrary.Data.Database
的用法示例。
在下文中一共展示了Database.AddParameter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildDBParameterForReturnValue
/// <summary>
/// 为储存过程加载输出变量参数
/// </summary>
/// <param name="db">database</param>
/// <param name="dbCommand">db command</param>
/// <param name="cmdParms">参数数组</param>
public static void BuildDBParameterForReturnValue(Database db, DbCommand dbCommand, params IDataParameter[] cmdParms)
{
foreach (SqlParameter sp in cmdParms)
{
db.AddParameter(dbCommand, sp.ParameterName, sp.DbType, sp.Size, ParameterDirection.Output, false, 0, 0, sp.SourceColumn, DataRowVersion.Current, DBNull.Value);
}
}
示例2: CreateReturnParameter
/// <summary>
/// Creates a return parameter and inserts into the command list
/// </summary>
/// <param name="db">The database object</param>
/// <param name="cmd">The command object</param>
/// <remarks>The DBCommand parameter argument that is modified</remarks>
public static void CreateReturnParameter(Database db, ref DbCommand cmd)
{
#region Defensive
#region db
Debug.Assert(db != null, "The argument supplied for parameter 'db' should not be null");
if(db == null)
{
throw new ArgumentNullException("db", "The argument supplied for parameter 'db' should not be null");
}
#endregion
#region cmd
Debug.Assert(cmd != null, "The argument supplied for parameter 'cmd' should not be null");
if(cmd == null)
{
throw new ArgumentNullException("cmd", "The argument supplied for parameter 'cmd' should not be null");
}
#endregion
#endregion
db.AddParameter(cmd, RETURN_VALUE, DbType.Int32, sizeof(int), ParameterDirection.ReturnValue,
false, 0, 0, string.Empty, DataRowVersion.Default, null);
}
示例3: AddOutParameter
public void AddOutParameter(Database database, string parameterName)
{
database.AddParameter(dbCommand, parameterName, DbType.Int32,
ParameterDirection.ReturnValue, null,
DataRowVersion.Default, null);
}
示例4: AddInParameter
public void AddInParameter(Database database, object value, string parameterName)
{
database.AddParameter(dbCommand, parameterName,
DbType.String, ParameterDirection.Input,
null, DataRowVersion.Default, value);
}
示例5: RunProcedureWithResult
/// <summary>
/// 执行存储过程,获得存储过程的返回值[注:必须在目标存储过程中设置return返回值,否则始终返回0]
/// </summary>
/// <param name="dc">存储过程语句</param>
/// <param name="db">操作目标数据库</param>
/// <returns></returns>
public static int RunProcedureWithResult(DbCommand dc, Database db)
{
int result = 0;
try
{
PrepareCommand(ref dc, db);
db.AddParameter(dc, "ReturnValue", DbType.Int32, ParameterDirection.ReturnValue, string.Empty, DataRowVersion.Default, null);
db.ExecuteNonQuery(dc);
result = (int)dc.Parameters[db.BuildParameterName("ReturnValue")].Value;
}
catch (System.Exception e)
{
throw new Exception(e.Message);
}
return result;
}
示例6: PrepareCommand
/// <summary>
/// Prepare a DbCommand object with its parameters
/// </summary>
/// <param name="pStoredProcedureName">Stored procedure name using dbo.Name sintax</param>
/// <param name="pParameters">Array of cParametroDatos</param>
/// <param name="pOutputParameters">List of DataParameters that are for output purpose</param>
/// <param name="pDbAccess">Database Object</param>
/// <returns>Prepared DbCommand</returns>
protected virtual DbCommand PrepareCommand(string pStoredProcedureName, IEnumerable<cParametroDatos> pParameters, out IList<cParametroDatos> pOutputParameters, out Database pDbAccess)
{
pDbAccess = GetDatabase();
DbCommand command = pDbAccess.GetStoredProcCommand(pStoredProcedureName);
pOutputParameters = new List<cParametroDatos>();
pOutputParameters.Add(new cParametroDatos(RETURN_VALUE, DbType.Int32, ParameterDirection.ReturnValue, 0));
SqlParameter param = new SqlParameter(RETURN_VALUE, SqlDbType.Int);
param.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(param);
foreach (cParametroDatos parameter in pParameters)
{
pDbAccess.AddParameter(command, parameter.ParameterName, parameter.DbType, parameter.Direction, parameter.ParameterName, DataRowVersion.Current, parameter.Value);
if (parameter.Direction == ParameterDirection.Output || parameter.Direction == ParameterDirection.InputOutput)
{
pOutputParameters.Add(parameter);
}
}
return command;
}