Ejemplo n.º 1
0
        public Return<object> ExecuteScalar()
        {
            if (_commandText.Contains(Constants.SEPARATOR)) { return ExecuteMultipleScalar(); }

            object cmdResult = null;

            using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(_connectionString))
            {
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(_commandText, cn);

                try
                {
                    cn.Open();

                    if (_isStoredProcedure)
                        cmd.CommandType = CommandType.StoredProcedure;

                    if (_parametersList.Count != 0)
                    {
                        foreach (KeyValuePair<string, object> parameter in _parametersList)
                        {
                            cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
                        }
                    }

                    _parameters = cmd.Parameters;

                    if (_noTimeOut)
                        cmd.CommandTimeout = 0;

                    cmdResult = cmd.ExecuteScalar();

                    cn.Close();

                    if (_ioSystem == null)
                        return new Return<object>(Return<object>.ResultEnum.Success, "", _app, "", cmdResult);
                    else
                        return new Return<object>(Return<object>.ResultEnum.Success, "", _ioSystem, "", cmdResult);
                }
                catch (Exception ex)
                {
                    if (_ioSystem == null)
                        return new Return<object>(Return<object>.ResultEnum.Failure, ex.Message, _app, "", cmdResult);
                    else
                        return new Return<object>(Return<object>.ResultEnum.Failure, ex.Message, _ioSystem, "", cmdResult);
                }
            }
        }
Ejemplo n.º 2
0
        public Return<bool> ExecuteNonQuery()
        {
            using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(_connectionString))
            {
                System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(_commandText, cn);
                int rowsAffected = 0;
                try
                {
                    cn.Open();

                    if (_isStoredProcedure)
                        cmd.CommandType = CommandType.StoredProcedure;

                    if (_parametersList.Count != 0)
                    {
                        foreach (KeyValuePair<string, object> parameter in _parametersList)
                        {
                            cmd.Parameters.AddWithValue(parameter.Key, parameter.Value);
                        }
                    }

                    _parameters = cmd.Parameters;

                    if (_noTimeOut)
                        cmd.CommandTimeout = 0;

                    rowsAffected = cmd.ExecuteNonQuery();

                    cn.Close();

                    if (_ioSystem == null)
                        return new Return<bool>(Return<bool>.ResultEnum.Success, rowsAffected.ToString(), _app, "", true);
                    else
                        return new Return<bool>(Return<bool>.ResultEnum.Success, rowsAffected.ToString(), _ioSystem, "", true);
                }
                catch (Exception ex)
                {
                    if (_ioSystem == null)
                        return new Return<bool>(Return<bool>.ResultEnum.Failure, ex.Message, _app, "", false);
                    else
                        return new Return<bool>(Return<bool>.ResultEnum.Failure, ex.Message, _ioSystem, "", false);
                }
            }
        }