Ejemplo n.º 1
0
        public static DataTable ExecuteQuery(this BaseDatabase database, string query, params IDbDataParameter[] parameters)
        {
            DataTable dataTable = new DataTable();

            using (IDbConnection connection = database.CreateConnection())
            {
                using (IDbCommand command = database.CreateCommand(query))
                {
                    command.Connection = connection;
                    connection.Open();

                    foreach (IDbDataParameter param in parameters)
                    {
                        command.Parameters.Add(param);
                    }

                    using (IDataReader dataReader = command.ExecuteReader())
                    {
                        dataTable.Load(dataReader);
                    }
                }
            }

            return(dataTable);
        }
Ejemplo n.º 2
0
        public static int ExecuteNonQuery(this BaseDatabase database, string query)
        {
            int rowsAffected = -1;

            using (IDbConnection connection = database.CreateConnection())
            {
                using (IDbCommand command = database.CreateCommand(query))
                {
                    command.Connection = connection;
                    connection.Open();
                    rowsAffected = command.ExecuteNonQuery();
                }
            }

            return(rowsAffected);
        }
Ejemplo n.º 3
0
        public static object ExecuteScalar(this BaseDatabase database, string query, params IDbDataParameter[] parameters)
        {
            object result = null;

            using (IDbConnection connection = database.CreateConnection())
            {
                using (IDbCommand command = database.CreateCommand(query))
                {
                    command.Connection = connection;
                    connection.Open();

                    foreach (IDbDataParameter param in parameters)
                    {
                        command.Parameters.Add(param);
                    }

                    result = command.ExecuteScalar();
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static int ExecuteNonQuery(this BaseDatabase database, string query, params IDbDataParameter[] parameters)
        {
            int rowsAffected = -1;

            using (IDbConnection connection = database.CreateConnection())
            {
                using (IDbCommand command = database.CreateCommand(query))
                {
                    command.Connection = connection;
                    connection.Open();

                    foreach (IDbDataParameter param in parameters)
                    {
                        command.Parameters.Add(param);
                    }

                    rowsAffected = command.ExecuteNonQuery();
                }
            }

            return(rowsAffected);
        }