コード例 #1
0
        public SqlGTResults Execute(string procedureName)
        {
            SqlGTResults results = new SqlGTResults();

            cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString);
            if (cnn.State != ConnectionState.Open)
            {
                cnn.Open();
            }
            return(this.Execute(cnn, procedureName));
        }
コード例 #2
0
        public SqlGTResults Execute(SqlConnection connection,
                                    string procedureName)
        {
            SqlGTResults results = new SqlGTResults();

            // Configure the SqlCommand and SqlParameter.
            SqlCommand insertCommand = new SqlCommand(procedureName, connection);

            insertCommand.CommandType = CommandType.StoredProcedure;
            foreach (object p in this.InputParameters.Keys)
            {
                insertCommand.Parameters.AddWithValue("@" + p, this.InputParameters[p]);
            }
            foreach (object p in this.InputList.Keys)
            {
                SqlParameter tvpParam = insertCommand.Parameters.AddWithValue("@" + p,
                                                                              SqlGTUtil.ConvertToDataTable((List <object>)InputList[p]));
                tvpParam.SqlDbType = SqlDbType.Structured;
            }
            //caso tenha sessao aqui
            //e não tenha informado forçar
            if (!insertCommand.Parameters.Contains("SESSION_ID") &&
                this.session != null)
            {
                insertCommand.Parameters.AddWithValue("@SESSION_ID", this.session.Id);
            }


            //executar / pegar resultados
            System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(insertCommand);
            DataSet ds = new DataSet();

            adapter.Fill(ds);

            //pegar as tabelas de retorno
            foreach (DataTable dt in ds.Tables)
            {
                if (dt.Rows.Count == 0)
                {
                    continue;
                }
                //table name
                dt.TableName = (string)dt.Rows[0]["OPTION_OUTPUT_TABLE"];

                //tabela especial de resultados
                if ((string)dt.Rows[0]["OPTION_OUTPUT_TABLE"] == "RESULT")
                {
                    results.ResultCode      = (string)dt.Rows[0]["CODIGO"];
                    results.ResultType      = (string)dt.Rows[0]["TIPO"];
                    results.ResultMessage   = (string)dt.Rows[0]["MENSAGEM"];
                    results.ResultException = (string)dt.Rows[0]["EXCEPTION"];
                }
                //para cada datable remove coluna de apoio
                dt.Columns.Remove("OPTION_OUTPUT_TABLE");
                //adiciona
                results.Tables.Add(dt);
            }
            if (results.ResultCode == null)
            {
                throw new Exception("SqlGT: resposta invalida de procedure não contém dados de controle.");
            }
            if (!ds.Tables.Contains("DEFAULT"))
            {
                throw new Exception("SqlGT: resposta invalida de procedure não contém dados padrao de retorno.");
            }

            return(results);
        }