本文整理汇总了C#中IDbCommand.CreateParameter方法的典型用法代码示例。如果您正苦于以下问题:C# IDbCommand.CreateParameter方法的具体用法?C# IDbCommand.CreateParameter怎么用?C# IDbCommand.CreateParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbCommand
的用法示例。
在下文中一共展示了IDbCommand.CreateParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareInsertVersionCommand
public void PrepareInsertVersionCommand(IDbCommand command, DatabaseVersion version,
string failedUpgradeFromVersion, string failedUpgradeToVersion, string failedUpgradeError)
{
command.CommandText = "INSERT INTO \"Version\" (\"Product\", \"Version\", " +
"\"FailedUpgradeFromVersion\", \"FailedUpgradeToVersion\", \"FailedUpgradeError\") " +
"VALUES (:product, :version, :failedupgradefromversion, " +
":failedupgradetoversion, :failedupgradeerror)";
IDbDataParameter productParameter = command.CreateParameter();
IDbDataParameter versionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeFromVersionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeToVersionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeErrorParameter = command.CreateParameter();
command.Parameters.Add(productParameter);
command.Parameters.Add(versionParameter);
command.Parameters.Add(failedUpgradeFromVersionParameter);
command.Parameters.Add(failedUpgradeToVersionParameter);
command.Parameters.Add(failedUpgradeErrorParameter);
productParameter.ParameterName = "product";
productParameter.DbType = DbType.String;
productParameter.Size = 250;
versionParameter.ParameterName = "version";
versionParameter.DbType = DbType.String;
versionParameter.Size = 250;
failedUpgradeFromVersionParameter.ParameterName = "failedupgradefromversion";
failedUpgradeFromVersionParameter.DbType = DbType.String;
failedUpgradeFromVersionParameter.Size = 50;
failedUpgradeToVersionParameter.ParameterName = "failedupgradetoversion";
failedUpgradeToVersionParameter.DbType = DbType.String;
failedUpgradeToVersionParameter.Size = 50;
failedUpgradeErrorParameter.ParameterName = "failedupgradeerror";
failedUpgradeErrorParameter.DbType = DbType.String;
failedUpgradeErrorParameter.Size = 4000;
productParameter.Value = version.Product;
versionParameter.Value = version.Version;
if (failedUpgradeFromVersion != null)
{
failedUpgradeFromVersionParameter.Value = failedUpgradeFromVersion;
failedUpgradeToVersionParameter.Value = failedUpgradeToVersion;
failedUpgradeErrorParameter.Value = failedUpgradeError;
}
else
{
failedUpgradeFromVersionParameter.Value = DBNull.Value;
failedUpgradeToVersionParameter.Value = DBNull.Value;
failedUpgradeErrorParameter.Value = DBNull.Value;
}
}
示例2: PrepareInsertVersionCommand
public void PrepareInsertVersionCommand(IDbCommand command, DatabaseVersion version,
string failedUpgradeFromVersion, string failedUpgradeToVersion, string failedUpgradeError)
{
command.CommandText = "INSERT INTO Version (Product, Version, " +
"FailedUpgradeFromVersion, FailedUpgradeToVersion, FailedUpgradeError) " +
"VALUES (@Product, @Version, @FailedUpgradeFromVersion, " +
"@FailedUpgradeToVersion, @FailedUpgradeError)";
IDbDataParameter productParameter = command.CreateParameter();
IDbDataParameter versionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeFromVersionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeToVersionParameter = command.CreateParameter();
IDbDataParameter failedUpgradeErrorParameter = command.CreateParameter();
command.Parameters.Add(productParameter);
command.Parameters.Add(versionParameter);
command.Parameters.Add(failedUpgradeFromVersionParameter);
command.Parameters.Add(failedUpgradeToVersionParameter);
command.Parameters.Add(failedUpgradeErrorParameter);
productParameter.ParameterName = "@Product";
productParameter.DbType = DbType.String;
productParameter.Size = 250;
productParameter.ParameterName = "@Version";
versionParameter.DbType = DbType.String;
versionParameter.Size = 250;
failedUpgradeFromVersionParameter.ParameterName = "@FailedUpgradeFromVersion";
failedUpgradeFromVersionParameter.DbType = DbType.String;
failedUpgradeFromVersionParameter.Size = 50;
failedUpgradeToVersionParameter.ParameterName = "@FailedUpgradeToVersion";
failedUpgradeToVersionParameter.DbType = DbType.String;
failedUpgradeToVersionParameter.Size = 50;
failedUpgradeErrorParameter.ParameterName = "@FailedUpgradeError";
failedUpgradeErrorParameter.DbType = DbType.String;
failedUpgradeErrorParameter.Size = 4000;
productParameter.Value = version.Product;
versionParameter.Value = version.Version;
if (failedUpgradeFromVersion != null)
{
failedUpgradeFromVersionParameter.Value = failedUpgradeFromVersion;
failedUpgradeToVersionParameter.Value = failedUpgradeToVersion;
failedUpgradeErrorParameter.Value = failedUpgradeError;
}
else
{
failedUpgradeFromVersionParameter.Value = DBNull.Value;
failedUpgradeToVersionParameter.Value = DBNull.Value;
failedUpgradeErrorParameter.Value = DBNull.Value;
}
}
示例3: AddParameter
protected void AddParameter (IDbCommand cmd, string name, object v)
{
IDataParameter param = cmd.CreateParameter ();
param.ParameterName = name;
param.Value = v;
cmd.Parameters.Add (param);
}
示例4: dbcommandparameter
private void dbcommandparameter(IDbCommand dbcommand, string parameternombre)
{
IDbDataParameter dbDataParameter=dbcommand.CreateParameter();
dbDataParameter.ParameterName ="nombre";
dbDataParameter.Value=Value;
dbcommand.ExecuteNonQuery();
}
示例5: AddParameter
public static void AddParameter(IDbCommand dbCommand, string nombre, object value)
{
IDbDataParameter dbDataParameter=dbCommand.CreateParameter ();
dbDataParameter.ParameterName = nombre;
dbDataParameter.Value = value;
dbCommand.Parameters.Add (dbDataParameter);
}
示例6: AddParameter
/// <summary>
/// Adds the parameter the specifed command
/// </summary>
/// <param name="command">The command.</param>
/// <param name="name">The name.</param>
/// <param name="val">The val.</param>
protected void AddParameter(IDbCommand command, string name, object val)
{
IDbDataParameter parameter = command.CreateParameter();
parameter.ParameterName = paramPrefix + name;
parameter.Value = val ?? DBNull.Value;
command.Parameters.Add(parameter);
}
示例7: AddParameter
public static void AddParameter(IDbCommand cmd, string name, object value)
{
IDataParameter p = cmd.CreateParameter ();
p.ParameterName = name;
p.Value = value;
cmd.Parameters.Add (p);
}
示例8: AddCommandParameter
public void AddCommandParameter(IDbCommand cmd, int parameterIndex, string paramName, object paramValue,
Enum dataType)
{
IDbDataParameter param = cmd.CreateParameter();
if (dataType != null)
{
SetDataTypeToCommandParameter(param, dataType);
}
param.ParameterName = dbProvider.Metadata.GetParameterName(paramName);
if (paramValue != null)
{
param.Value = paramValue;
}
else
{
param.Value = DBNull.Value;
}
cmd.Parameters.Add(param);
if (dbProvider.Metadata.ParameterNamePrefix != "@")
{
// we need to replace
cmd.CommandText =
cmd.CommandText.Replace("@" + paramName, dbProvider.Metadata.ParameterNamePrefix + paramName);
}
}
示例9: FillDeleteCommand
/// <summary>
/// Preenche as propriedades e os parâmetros de um comando do ADO.NET, baseado
/// nos metadados contidos na DataTable, para construir um comando SQL DELETE.
/// </summary>
/// <param name="dt">A DataTable que contém os metadados</param>
/// <param name="paramReplacement">Substituidor do nome do parâmetro (usualmente <c>?</c>)</param>
/// <param name="cmd">O IDbCommand</param>
/// <returns>O mesmo IDbCommand recebido</returns>
public static IDbCommand FillDeleteCommand(DataTable dt, string paramReplacement, IDbCommand cmd)
{
if (dt.PrimaryKey.Length == 0)
throw new InvalidOperationException();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("DELETE FROM {0} WHERE ", dt.TableName);
foreach (DataColumn col in dt.PrimaryKey)
{
IDbDataParameter p = cmd.CreateParameter();
p.SourceColumn = col.ColumnName;
p.DbType = DbType.String;
p.Size = 255;
sb.AppendFormat("[{0}] = @{0} AND ", col.ColumnName);
cmd.Parameters.Add(p);
}
sb.Length -= (" AND ").Length;
Debug.WriteLine(sb.ToString());
cmd.CommandText = sb.ToString();
return ExpandParameters(cmd, paramReplacement);
}
示例10: Set
void SqlMapper.ICustomQueryParameter.AddParameter(IDbCommand command, string name)
{
var param = command.CreateParameter();
param.ParameterName = name;
Set(param, table, typeName);
command.Parameters.Add(param);
}
示例11: CreateDbParameter
public IDbDataParameter CreateDbParameter(IDbCommand command, IDbAdapter dbAdapter)
{
var result = command.CreateParameter();
result.ParameterName = dbAdapter.FormatParameterName(Name);
result.Value = dbAdapter.ConvertToDbType(Value);
return result;
}
示例12: BuildCommand
public static void BuildCommand(IDbCommand cmd, string sql, params object[] parameters)
{
if (cmd == null) throw new ArgumentNullException("cmd");
if (String.IsNullOrEmpty(sql)) throw new ArgumentNullException("sql");
if (parameters == null)
{
parameters = new object[0];
}
cmd.CommandText = new Regex(" *[\r\n]+ *").Replace(sql, " ");
var parameterNames = FindUniqueParameters(sql);
if (parameterNames.Count != parameters.Length)
{
throw new MicrOrmException(String.Format("Parameter count mismatch. {0} in the SQL string, {1} supplied", parameterNames.Count, parameters.Length));
}
for (var i = 0; i < parameters.Length; i++)
{
if (!parameterNames.ContainsKey(i))
{
throw new MicrOrmException(String.Format("Parameter ordinal mismatch. Parameter with ordinal {0} is missing in the SQL string", i));
}
var dbParameter = cmd.CreateParameter();
dbParameter.ParameterName = parameterNames[i];
dbParameter.Value = parameters[i];
cmd.Parameters.Add(dbParameter);
}
}
示例13: Initialize
public override void Initialize(IDatabaseEngine engine, IDbCommand command)
{
string innerParameterName = engine.GetParameterName(ParameterName);
sqlSnippet = sqlSnippet.Replace(REPLACEMENT_VALUE, innerParameterName);
_innerParameter = command.CreateParameter();
_innerParameter.ParameterName = innerParameterName;
}
示例14: AddParameter
private static void AddParameter(IDbCommand cmd, object param)
{
IDbDataParameter p;
p = param as IDbDataParameter;
if (p != null)
{
cmd.Parameters.Add(p);
return;
}
p = cmd.CreateParameter();
p.ParameterName = cmd.Parameters.Count.ToString();
if (param == null)
{
p.Value = DBNull.Value;
}
else
{
p.Value = param;
// make strings a consistent size, helps with query plan caching.
if (param.GetType() == typeof(string) && p.Size < 4000)
{
p.Size = 4000;
}
}
cmd.Parameters.Add(p);
}
示例15: AddParameter
private static void AddParameter(IDbCommand command, string name, object value)
{
var parameter = command.CreateParameter();
parameter.ParameterName = name;
parameter.Value = value;
command.Parameters.Add(parameter);
}