Beispiel #1
0
        public override bool OfOpenDb()
        {
            try
            {
                if (DBConntion == null)
                {
                    return(false);
                }

                if (DBConntion.State == ConnectionState.Open)
                {
                    return(true);
                }

                if (DBConntion.State != ConnectionState.Open)
                {
                    DBConntion.Open();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// 傳入 SQL String 返回 DataSet
        /// </summary>
        /// <param name="ps_sql">SQL String</param>
        /// <param name="pdt_return">DataTable</param>
        /// <returns></returns>
        public override int OfExecuteDatatable(DbTransaction ptran, string ps_sql, ref DataTable pdt_return)
        {
            if (!this.OfOpenDb())
            {
                return(-1);
            }

            if (!this.OfOpenDb())
            {
                return(-1);
            }


            if (pdt_return == null)
            {
                pdt_return = new DataTable();
            }

            SqlConnection lcon = null;

            // OleDbTransaction l_oletran = this.m_oledb_cn.BeginTransaction();
            if (ptran != null && ptran.Connection != null)
            {
                lcon = ((SqlTransaction)ptran).Connection;
            }
            else
            {
                lcon = (SqlConnection)this.DBConntion;
            }
            using (SqlDataAdapter lda = new SqlDataAdapter(ps_sql, lcon))
            {
                if (this.DBConntion.State != ConnectionState.Open)
                {
                    DBConntion.Open();
                }

                pdt_return.Rows.Clear();
                lda.Fill(pdt_return);
                //l_oletran.Commit();
            }


            if (pdt_return != null)
            {
                return(pdt_return.Rows.Count);
            }

            return(-1);
        }