System.Data.Common.DbParameterCollection.Contains(string)

Here are the examples of the csharp api class System.Data.Common.DbParameterCollection.Contains(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

1. Example

View license
protected override DbParameter GetParameter(string parameterName)
        {
            if (_dbParameterCollection != null && _dbParameterCollection.Contains(parameterName))
            {
                return _dbParameterCollection[parameterName];
            }

            if (_parameterCollection.Contains(parameterName))
            {
                return new DbParameterWrapper(_parameterCollection[parameterName] as IDbDataParameter);
            }

            return null;
        }

2. Example

Project: AntiSQLi
Source File: DbCommandWrapper.cs
View license
public bool ContainsParameter(String Name)
        {
            return (
                !String.IsNullOrEmpty(Name) &&
                (SqlCommandObject.Parameters.Contains(Name))
                );
        }

3. Example

Project: scada
Source File: DataSource.cs
View license
public void SetCmdParam(DbCommand cmd, string paramName, object value)
        {
            if (cmd == null)
                throw new ArgumentNullException("cmd");

            if (cmd.Parameters.Contains(paramName))
                cmd.Parameters[paramName].Value = value;
            else
                AddCmdParamWithValue(cmd, paramName, value);
        }

4. Example

View license
public static DbParameter GetOrCreateParameter(this DbCommand Command, string ID)
        {
            if (Command == null)
                return null;
            if (Command.Parameters.Contains(ID))
                return Command.Parameters[ID];
            var Parameter = Command.CreateParameter();
            Parameter.ParameterName = ID;
            Command.Parameters.Add(Parameter);
            return Parameter;
        }

5. Example

View license
public static DbParameter GetOrCreateParameter(this DbCommand Command, string ID)
        {
            if (Command == null)
                return null;
            if (Command.Parameters.Contains(ID))
                return Command.Parameters[ID];
            var Parameter = Command.CreateParameter();
            Parameter.ParameterName = ID;
            Command.Parameters.Add(Parameter);
            return Parameter;
        }

6. Example

Project: XCLCMS
Source File: Common.cs
View license
public static XCLCMS.Data.Model.Custom.ProcedureResultModel GetProcedureResult(DbParameterCollection parameters)
        {
            XCLCMS.Data.Model.Custom.ProcedureResultModel model = new XCLCMS.Data.Model.Custom.ProcedureResultModel();
            model.IsSuccess = true;

            if (null != parameters && parameters.Count > 0)
            {
                if (parameters.Contains("@ResultCode"))
                {
                    model.ResultCode = Int32.Parse(Convert.ToString(parameters["@ResultCode"].Value));
                    model.IsSuccess = (model.ResultCode == 1);
                }
                if (parameters.Contains("@ResultMessage"))
                {
                    model.ResultMessage = Convert.ToString(parameters["@ResultMessage"].Value);
                }
            }

            return model;
        }

7. Example

Project: ALinq
Source File: CommandBuilder.cs
View license
internal override SqlExpression VisitParameter(SqlParameter p)
        {
            if (!command.Parameters.Contains(p.Name))
            {
                parameter = command.CreateParameter();
                parameter.ParameterName = p.Name;
                command.Parameters.Add(parameter);
                parameter.Value = (from parameterInfo in parameterInfos
                                   where parameterInfo.Parameter.Name == parameter.ParameterName
                                   select parameterInfo.Value).FirstOrDefault() ?? DBNull.Value;
                if (parameter.Value != null && parameter.Value.GetType() == typeof(Binary))
                {
                    parameter.DbType = DbType.Binary;
                    parameter.Value = ((Binary) parameter.Value).ToArray();
                }
                if (parameter.DbType == DbType.DateTime)
                    parameter.DbType = DbType.String;
            }
            return base.VisitParameter(p);
        }

8. Example

Project: nuodb-dotnet
Source File: ProcFixture.cs
View license
[Test]
        public void TestPrepareParamOut()
        {
            using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
            {
                connection.Open();
                new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
                new NuoDbCommand("create procedure nunit_test(out p1 string) as p1='hello'; end_procedure", connection).ExecuteNonQuery();

                NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Prepare();
                Assert.IsTrue(cmd.Parameters.Contains("p1"));
                Assert.AreEqual(ParameterDirection.Output, cmd.Parameters["p1"].Direction);
                cmd.ExecuteNonQuery();
                Assert.AreEqual("hello", cmd.Parameters["p1"].Value);
            }
        }

9. Example

Project: nuodb-dotnet
Source File: ProcFixture.cs
View license
[Test]
        public void TestPrepareParamInOut()
        {
            using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
            {
                connection.Open();
                new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
                new NuoDbCommand("create procedure nunit_test(inout p1 string) as if(p1='goodbye') p1='hello'; end_if; end_procedure", connection).ExecuteNonQuery();

                NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Prepare();
                Assert.IsTrue(cmd.Parameters.Contains("p1"));
                Assert.AreEqual(ParameterDirection.InputOutput, cmd.Parameters["p1"].Direction);
                cmd.Parameters["p1"].Value = "goodbye";
                cmd.ExecuteNonQuery();
                Assert.AreEqual("hello", cmd.Parameters["p1"].Value);
            }
        }

10. Example

Project: ALinq
Source File: CommandBuilder.cs
View license
internal override SqlExpression VisitParameter(SqlParameter p)
        {
            if (!command.Parameters.Contains(p.Name))
            {
                Debug.Assert(p.Name.StartsWith("@"));
                parameter = command.CreateParameter();
                command.Parameters.Add(parameter);
                parameter.Value = (from parameterInfo in parameterInfos
                                   where parameterInfo.Parameter.Name == p.Name
                                   select parameterInfo.Value).FirstOrDefault() ?? DBNull.Value;

                if (parameter.Value != null)
                {
                    if (parameter.Value.GetType() == typeof(Binary))
                    {
                        parameter.DbType = DbType.Binary;
                        parameter.Value = ((Binary)parameter.Value).ToArray();
                    }
                    else if (parameter.Value.GetType() == typeof(Guid))
                    {
                        parameter.DbType = DbType.Binary;
                        parameter.Value = ((Guid)parameter.Value).ToByteArray();
                    }
                }
                parameter.ParameterName = ":" + p.Name.Substring(1);
            }
            return base.VisitParameter(p);
        }

11. Example

Project: nuodb-dotnet
Source File: ProcFixture.cs
View license
[Test]
        public void TestPrepareParamIn()
        {
            using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
            {
                connection.Open();
                new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
                new NuoDbCommand("create procedure nunit_test(in p1 string) as throw p1; end_procedure", connection).ExecuteNonQuery();

                NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Prepare();
                Assert.IsTrue(cmd.Parameters.Contains("p1"));
                Assert.AreEqual(ParameterDirection.Input, cmd.Parameters["p1"].Direction);
                cmd.Parameters["p1"].Value = "hello";
                try
                {
                    cmd.ExecuteNonQuery();
                    Assert.Fail();
                }
                catch (Exception e)
                {
                    Assert.IsTrue(e.Message.Contains("hello"), "Expected error: 'hello', received "+e.Message);
                }
            }
        }