[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

How Do You Retrieve the Results Back from an Oracle Stored Procedure in .NET?

I wrote a stored procedure in C# .NET to retrieve the batch process id back in a string format.  

What is the correct way to write a method to retrieve the batch process if back in a string format?

Here is my method:

// Stored Procedure to Retrieve Batch Process Id
public static string GenerateBatchProcessId()
{
            // Setting Oracle Connection String and Opening the Connection
            OracleCommand cmd;
            OracleConnection connection = new OracleConnection(Constants.ConnectionString);
            connection.Open();
            cmd = new OracleCommand();
            cmd.Connection = connection;

            string batchProcessId = "";

            IDbCommand command = new OracleCommand();

            //command.Parameters.Add(new OracleParameter("p_CSS_APP_ID", OracleDbType.Int64, appId, ParameterDirection.Input));
            //command.Parameters.Add(new OracleParameter("p_BUS_BATCH_PROCESS_ID", OracleDbType.Varchar2, batchProcessId, ParameterDirection.Input));

            cmd.CommandText = "CSS_BLS_TAXL_OPEN_MAINT_PKG.GET_BATCH_PROCESS_ID";
            cmd.CommandType = CommandType.StoredProcedure;
            batchProcessId = cmd.ExecuteNonQuery().ToString();

            return batchProcessId;
}

Please provide a solution.  This method needs to return a batch Id from a stored procedure in string format.

Thanks,

Dan
0
danielolorenz
Asked:
danielolorenz
  • 3
  • 2
1 Solution
 
djon2003Commented:
The ExecuteNonQuery method doesn't return any value.

To do so, you should use a DataAdaptor (da) and a DataSet (ds) like this :
            da.SelectCommand = cmd
            da.Fill(ds, tableMappingName)

Open in new window


This code is in VB.NET, though really similar to C#.
0
 
danielolorenzAuthor Commented:
Is there a way to return the results just to a string?
0
 
djon2003Commented:
By using
String myVar = cmd.ExecuteScalar();

Open in new window

0
 
djon2003Commented:
This returns in fact the first row first column of the above DataSet
0
 
danielolorenzAuthor Commented:
Thanks
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now