Exemple #1
0
        public Int64 ExecuteInsertReturnId(DBQuery query)
        {
            Int64 result = 0;

            if (query.Transaction != null)
            {
                try
                {
                    OracleCommand Command = query.Transaction.Connection.CreateCommand();
                    Command.Transaction = query.Transaction.Transaction;
                    Command.CommandType = CommandType.Text;
                    Command.CommandText = query.text;
                    Command.BindByName  = true;
                    foreach (string key in query.parameters.Keys)
                    {
                        if (query.parameters[key] != null)
                        {
                            Command.Parameters.Add(new OracleParameter(key, query.parameters[key]));
                        }
                    }
                    OracleParameter outputParameter = new OracleParameter("RECORD_ID", OracleDbType.Int64);
                    outputParameter.Direction = ParameterDirection.Output;
                    Command.Parameters.Add(outputParameter);
                    int rowsAffected = Command.ExecuteNonQuery();
                    if (rowsAffected != 0)
                    {
                        result = long.Parse(outputParameter.Value.ToString()); // Convert.ToInt64(outputParameter.Value);
                    }
                    else
                    {
                        result = 0;
                    }
                }
                catch (Exception ex)
                {
                    result = 0;
                    Console.WriteLine(ex.Message);
                    throw (ex);
                }
                finally
                {
                }
            }
            else
            {
                using (OracleConnection connection = new OracleConnection(ConnectionHandler.buildConnectionString()))
                {
                    try
                    {
                        connection.Open();

                        OracleCommand Command = connection.CreateCommand();
                        Command.CommandType = CommandType.Text;
                        Command.CommandText = query.text;
                        Command.BindByName  = true;
                        foreach (string key in query.parameters.Keys)
                        {
                            if (query.parameters[key] != null)
                            {
                                Command.Parameters.Add(new OracleParameter(key, query.parameters[key]));
                            }
                        }
                        OracleParameter outputParameter = new OracleParameter("RECORD_ID", OracleDbType.Int64);
                        outputParameter.Direction = ParameterDirection.Output;
                        Command.Parameters.Add(outputParameter);
                        int rowsAffected = Command.ExecuteNonQuery();
                        if (rowsAffected != 0)
                        {
                            result = long.Parse(outputParameter.Value.ToString()); // Convert.ToInt64(outputParameter.Value);
                        }
                        else
                        {
                            result = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        result = 0;
                        Console.WriteLine(ex.Message);
                        throw (ex);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        public Boolean ExecuteInsert(DBQuery query)
        {
            Boolean result = true;

            if (query.Transaction != null)
            {
                try
                {
                    OracleCommand Command = query.Transaction.Connection.CreateCommand();
                    Command.Transaction = query.Transaction.Transaction;
                    Command.CommandType = CommandType.Text;
                    Command.CommandText = query.text;
                    Command.BindByName  = true;
                    foreach (string key in query.parameters.Keys)
                    {
                        Command.Parameters.Add(new OracleParameter(key, query.parameters[key]));
                    }
                    int rowsAffected = Command.ExecuteNonQuery();
                    result = (rowsAffected == 0) ? false : true;
                }
                catch (Exception ex)
                {
                    result = false;
                    Console.WriteLine(ex.Message);
                    throw (ex);
                }
                finally
                {
                }
            }
            else
            {
                using (OracleConnection connection = new OracleConnection(ConnectionHandler.buildConnectionString()))
                {
                    try
                    {
                        connection.Open();

                        OracleCommand Command = connection.CreateCommand();
                        Command.CommandType = CommandType.Text;
                        Command.CommandText = query.text;
                        Command.BindByName  = true;
                        foreach (string key in query.parameters.Keys)
                        {
                            Command.Parameters.Add(new OracleParameter(key, query.parameters[key]));
                        }
                        int rowsAffected = Command.ExecuteNonQuery();
                        result = (rowsAffected == 0) ? false : true;
                    }
                    catch (Exception ex)
                    {
                        result = false;
                        Console.WriteLine(ex.Message);
                        throw (ex);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }

            return(result);
        }