Exemple #1
0
        /// <summary>
        ///     Executes a DataSet.
        /// </summary>
        /// <param name="edt">Database provider dataType</param>
        /// <param name="connectionString">Connection string</param>
        /// <param name="executableQuery">Query to be executed</param>
        /// <returns>DataSet</returns>
        public DataTable ExecuteDataTable(DatabaseServer edt, string connectionString, ExecutionQuery executableQuery)
        {
            DbConnection  icon = null;
            DbCommand     icmd = null;
            DataTable     dset = null;
            DbDataAdapter idap = null;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);
                factory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icmd.Connection = icon;
                dset            = new DataTable();

                icon.ConnectionString = connectionString;

                icmd.Parameters.Clear();

                if (executableQuery.Parameters != null)
                {
                    foreach (IDataParameter var in executableQuery.Parameters)
                    {
                        icmd.Parameters.Add(var);
                    }
                }

                icmd.CommandText   = executableQuery.Query;
                idap.SelectCommand = icmd;

                //log the queries
                (new ExecutionEngineLogger()).LogContext(executableQuery);

                icon.Open();

                idap.Fill(dset);

                return(dset);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
Exemple #2
0
        /// <summary>
        ///     Executes a DataTable
        /// </summary>
        /// <param name="edt">Provider Type</param>
        /// <param name="connectionString">Connection Strinng</param>
        /// <param name="storedProcedure">Stored Procedure's name</param>
        /// <param name="iparam">Stored Procedure Data Parameters</param>
        /// <returns>DataSet</returns>
        public DataTable ExecuteDataTable(DatabaseServer edt, string connectionString, string storedProcedure, params IDataParameter[] iparam)
        {
            DbConnection  icon  = null;
            DbCommand     icmd  = null;
            DataTable     table = null;
            DbDataAdapter idap  = null;

            DataFactory factory = new DataFactory();

            try
            {
                factory.InitializeDbConnection(edt, ref icon);
                factory.InitializeDbCommand(edt, ref icmd);
                factory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icon.ConnectionString = connectionString;
                icmd.Connection       = icon;
                icon.Open();

                table = new DataTable();

                if (iparam != null)
                {
                    for (int i = 0; i < iparam.Length; i++)
                    {
                        icmd.Parameters.Add(iparam[i]);
                    }
                }

                //log the message
                (new ExecutionEngineLogger()).LogContext(storedProcedure);

                icmd.CommandType = CommandType.StoredProcedure;
                icmd.CommandText = storedProcedure;

                idap.SelectCommand = icmd;
                idap.Fill(table);

                return(table);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }
Exemple #3
0
        public static void ExecuteDataSet(DatabaseServer edt, string connectionString, ExecutionQuery executableQuery, ref DataSet ds)
        {
            DbConnection  icon = null;
            DbCommand     icmd = null;
            DbDataAdapter idap = null;

            try
            {
                DataFactory.InitializeDbConnection(edt, ref icon);
                DataFactory.InitializeDbCommand(edt, ref icmd);
                DataFactory.InitializeDbDataAdapter(edt, ref idap, icmd);

                icmd.Connection = icon;


                icon.ConnectionString = connectionString;

                icmd.Parameters.Clear();

                if (executableQuery.Parameters != null)
                {
                    foreach (IDataParameter var in executableQuery.Parameters)
                    {
                        icmd.Parameters.Add(var);
                    }
                }

                icmd.CommandType = CommandType.Text;
                icmd.CommandText = executableQuery.Query;

                idap.SelectCommand = icmd;

                //log the query
                (new ExecutionEngineLogger()).LogContext(executableQuery);

                icon.Open();

                idap.Fill(ds);
            }
            finally
            {
                DisposeObjects(ref icon, ref icmd);
            }
        }