Ejemplo n.º 1
0
        public static object SqlScalartoObj(string sqlQuery, DbSqlParameterCollection sqlParams)
        {
            bool       isTransaction = IsTransaction;
            SqlCommand myCommand     = new SqlCommand(sqlQuery, (isTransaction) ? GetConnection : GetNewConnection);

            foreach (DbSqlParameter p in sqlParams)
            {
                myCommand.Parameters.Add(p.Parameter);
            }
            if (myCommand.Connection.State != ConnectionState.Open)
            {
                myCommand.Connection.Open();
            }
            if (isTransaction)
            {
                if (currentTransaction != null)
                {
                    myCommand.Transaction = currentTransaction;
                }
            }
            else
            {
                object ret = myCommand.ExecuteScalar();
                myCommand.Connection.Close();
                return(ret);
            }
            return(myCommand.ExecuteScalar());
        }
Ejemplo n.º 2
0
        public static DataSet SecureCreateDataset(string sqlString, DbSqlParameter param)
        {
            DbSqlParameterCollection p = new DbSqlParameterCollection();

            p.Add(param);
            return(SecureCreateDataset(sqlString, p));
        }
Ejemplo n.º 3
0
        public static DataTable DoStoredTable(string sqlStored, DbSqlParameterCollection sqlParams)
        {
            bool       isTransaction = IsTransaction;
            SqlCommand myCommand     = new SqlCommand(sqlStored, (isTransaction)?DatabaseConnection.GetConnection:DatabaseConnection.GetNewConnection);

            myCommand.CommandType = CommandType.StoredProcedure;
            foreach (DbSqlParameter p in sqlParams)
            {
                myCommand.Parameters.Add(p.Parameter);
            }
            if (myCommand.Connection.State != ConnectionState.Open)
            {
                myCommand.Connection.Open();
            }
            if (isTransaction)
            {
                myCommand.Transaction = currentTransaction;
            }

            SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
            DataTable      dt      = new DataTable();

            adapter.Fill(dt);

            return(dt);
        }
Ejemplo n.º 4
0
        public static object DoStoredScalar(string sqlStored, DbSqlParameterCollection sqlParams, bool transactional)
        {
            SqlCommand myCommand = new SqlCommand(sqlStored, (transactional)?DatabaseConnection.GetConnection:DatabaseConnection.GetNewConnection);

            myCommand.CommandType = CommandType.StoredProcedure;
            foreach (DbSqlParameter p in sqlParams)
            {
                myCommand.Parameters.Add(p.Parameter);
            }
            if (myCommand.Connection.State != ConnectionState.Open)
            {
                myCommand.Connection.Open();
            }
            if (transactional)
            {
                if (currentTransaction != null)
                {
                    myCommand.Transaction = currentTransaction;
                }
            }
            else
            {
                object ret = myCommand.ExecuteScalar();
                myCommand.Connection.Close();
                return(ret);
            }
            return(myCommand.ExecuteScalar());
        }
Ejemplo n.º 5
0
        public static void DoCommand(string sql, DbSqlParameterCollection sqlParams)
        {
            SqlCommand cmd = new SqlCommand(sql, GetConnection);

            try
            {
                if (cmd.Connection.State != ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }
                if (currentTransaction != null)
                {
                    cmd.Transaction = currentTransaction;
                }
                foreach (DbSqlParameter p in sqlParams)
                {
                    cmd.Parameters.Add(p.Parameter);
                }
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
            }
        }
Ejemplo n.º 6
0
        public static SqlDataReader CreateReader(string sqlString, DbSqlParameterCollection sqlParams)
        {
            SqlCommand    myCmd = new SqlCommand(sqlString, (IsTransaction)?GetConnection:GetNewConnection);
            SqlDataReader dr    = null;

            if (myCmd.Connection.State != ConnectionState.Open)
            {
                myCmd.Connection.Open();
            }
            if (currentTransaction != null)
            {
                myCmd.Transaction = currentTransaction;
            }

            foreach (DbSqlParameter par in sqlParams)
            {
                myCmd.Parameters.Add(par.Parameter);
            }
            dr = myCmd.ExecuteReader(CommandBehavior.CloseConnection);
            return(dr);
        }
Ejemplo n.º 7
0
        public static void DoStored(string sqlStored, DbSqlParameterCollection sqlParams, bool transactional)
        {
            SqlCommand myCommand = new SqlCommand(sqlStored, (transactional)?DatabaseConnection.GetConnection:DatabaseConnection.GetNewConnection);

            myCommand.CommandType = CommandType.StoredProcedure;
            foreach (DbSqlParameter p in sqlParams)
            {
                myCommand.Parameters.Add(p.Parameter);
            }
            if (myCommand.Connection.State != ConnectionState.Open)
            {
                myCommand.Connection.Open();
            }
            if (currentTransaction != null)
            {
                myCommand.Transaction = currentTransaction;
            }
            myCommand.ExecuteNonQuery();
            if (!IsTransaction)
            {
                myCommand.Connection.Close();
            }
        }
Ejemplo n.º 8
0
        public static DataSet SecureCreateDataset(string sqlString, DbSqlParameterCollection sqlParams)
        {
            DataSet    Secure = new DataSet();
            SqlCommand cmd    = (IsTransaction)?GetConnection.CreateCommand():GetNewConnection.CreateCommand();

            cmd.CommandText = sqlString;
            SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(cmd);

            if (IsTransaction)
            {
                SqlDataAdapter.SelectCommand.Transaction = currentTransaction;
            }
            foreach (DbSqlParameter ss in sqlParams)
            {
                cmd.Parameters.Add(ss.Parameter);
            }
            try
            {
                if (cmd.Connection.State != ConnectionState.Open)
                {
                    cmd.Connection.Open();
                }
                if (currentTransaction != null)
                {
                    cmd.Transaction = currentTransaction;
                }
                SqlDataAdapter.Fill(Secure);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
            }
            return(Secure);
        }
Ejemplo n.º 9
0
 public static void DoStored(string sqlStored, DbSqlParameterCollection sqlParams)
 {
     DoStored(sqlStored, sqlParams, IsTransaction);
 }