当前位置: 首页>>代码示例>>C#>>正文


C# IDbCommand.CreateParameter方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:gregorypilar,项目名称:interlace,代码行数:56,代码来源:NpgsqlDatabaseImplementation.cs

示例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;
            }
        }
开发者ID:gregorypilar,项目名称:interlace,代码行数:56,代码来源:SqlDatabaseImplementation.cs

示例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);
		}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:DbEntry.cs

示例4: dbcommandparameter

 private void dbcommandparameter(IDbCommand dbcommand, string parameternombre)
 {
     IDbDataParameter dbDataParameter=dbcommand.CreateParameter();
     dbDataParameter.ParameterName ="nombre";
     dbDataParameter.Value=Value;
     dbcommand.ExecuteNonQuery();
 }
开发者ID:jonathanortizdam1993445,项目名称:ed,代码行数:7,代码来源:CategoriaView.cs

示例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);
 }
开发者ID:DiegoDeBelda,项目名称:AD,代码行数:7,代码来源:DbCommandHelper.cs

示例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);
 }
开发者ID:madmonkey,项目名称:rhino-etl,代码行数:13,代码来源:AbstractDatabaseOperation.cs

示例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);
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:7,代码来源:DatabaseUtility.cs

示例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);
            }
        }
开发者ID:kisflying,项目名称:kion,代码行数:26,代码来源:AdoUtil.cs

示例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);
		}
开发者ID:elementar,项目名称:Suprifattus.Util,代码行数:35,代码来源:DataSetTools.cs

示例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);
 }
开发者ID:CarlSosaDev,项目名称:dapper-dot-net,代码行数:7,代码来源:TableValuedParameter.cs

示例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;
 }
开发者ID:Wijlini,项目名称:catnap-orm,代码行数:7,代码来源:Parameter.cs

示例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);
            }
        }
开发者ID:ChrisMH,项目名称:HoganUtilities,代码行数:30,代码来源:QueryBuilder.cs

示例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;
 }
开发者ID:hp4711,项目名称:structuremap,代码行数:7,代码来源:ParameterizedQueryFilter.cs

示例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);
        }
开发者ID:snoopydo,项目名称:dksData,代码行数:31,代码来源:dksData.GetCommand.cs

示例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);
 }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:7,代码来源:ComplexCommandBuilder.cs


注:本文中的IDbCommand.CreateParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。