Question

Stored Procedure to Capture Results via Script

I am curious if anyone has returned output from a stored procedure via script within a business process?  I found one process with a script task that uses the StoredProcedure object to execute the stored procedure, but nothing to capture the output.  Is this possible under the bpm online platform objects?

 

CalcForecastFactPotentialProcess

if (ForecastId != Guid.Empty) {

StoredProcedure storedProcedure = new StoredProcedure(UserConnection, "tsp_RecalculateForecastFact")

.WithParameter("ForecastId", ForecastId) as StoredProcedure;

storedProcedure.PackageName = UserConnection.DBEngine.SystemPackageName;

if (CurrentUserContactId != Guid.Empty) {

storedProcedure.WithParameter("CurrentUserContactId", CurrentUserContactId);

}

storedProcedure.Execute();

CreateReminding();

}

return true;

 

 

Using Reader

SqlConnection connection = new SqlConnection(ConnectionString);

command = new SqlCommand("TestProcedure", connection);

command.CommandType = System.Data.CommandType.StoredProcedure;

connection.Open();

reader = command.ExecuteReader();

List TestList = new List();

Test test;

while (reader.Read())

{

    test = new Test();

    test.ID = int.Parse(reader["ID"].ToString());

    test.Name = reader["Name"].ToString();

    TestList.Add(test);

}

Use DataTable

SqlConnection connection = new SqlConnection(ConnectionString);

command = new SqlCommand("TestProcedure", connection);

command.CommandType = System.Data.CommandType.StoredProcedure;

connection.Open();

DataTable dt = new DataTable();

dt.Load(command.ExecuteReader());

gvGrid.DataSource = dt;

gvGrid.DataBind();

 

Steve

Like 0

Like

1 comments

Dear Steve,

Firstly, in order to get the result of a stored procedure, you need to add the following Using to the process:

Namespace: System.Data.IDataReader

Name: IDataReader

Also, to get the result of a stored procedure executing, you need to call it with the outgoing parameter.

The outgoing parameter: .WithOutputParameter ("ResultParameter", textDataValueType)

Get the result of stored procedure from the process parameter:

var resultParameter = (string) storedProcedure.Parameters.FindByName ("ResultParameter"). Value;

To use the .WithOutputParameter ("ResultParameter", textDataValueType) as StoredProcedure in the script, you need to register the stored procedure parameter as OUTPUT:

CREATE procedure [dbo]. [Tsp_test]
(@res_msg nvarchar (250) OUTPUT)
as
select @ res_msg = '1'
select @res_msg as res_msg
return @res_msg

Regards,

Anastasia

Show all comments