Calling Stored Procedures
You can invoke a stored procedure using Sage300Command in the same way as any other SQL stored procedure. To instantiate a Sage300Command object, provide the name of the stored procedure and a Sage300Connection instance as arguments to the constructor. Set the value of the CommandType property to "StoredProcedure" and add the parameters as key-value pairs to the Parameters collection of the Sage300Command instance.
C#
string connectionString = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;"; using (Sage300Connection connection = new Sage300Connection(connectionString)) { Sage300Command cmd = new Sage300Command("APCreateGLBatch", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new Sage300Parameter("@ProcessPaymentBatch", "DoNotPostPaymentBatches")); // Add other parameters as needed ... Sage300DataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { for (int i = 0; i < rdr.FieldCount; i++) { Console.WriteLine(rdr.GetName(i) + " --> " + rdr[i]); } Console.WriteLine(); } }
VB.NET
Dim connectionString As String = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;" Using connection As New Sage300Connection(connectionString) Dim cmd As New Sage300Command("APCreateGLBatch", connection) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.Add(New Sage300Parameter("@ProcessPaymentBatch", "DoNotPostPaymentBatches")) ' Add other parameters as needed ... Dim rdr As Sage300DataReader = cmd.ExecuteReader() While rdr.Read() For i As Integer = 0 To rdr.FieldCount - 1 Console.WriteLine(rdr.GetName(i) + " --> " + rdr(i)) Next Console.WriteLine() End While End Using
Alternatively, you can set the parameters of a stored procedure in the text of the command. The support for stored procedure statements follows the standard form shown below:
"EXECUTE my_proc @first = 1, @second = 2, @third = 3;" "EXEC my_proc @first = 1, @second = 2, @third = 3;"
To execute a parameterized query, add parameters as key-value pairs to the Parameters collection of the Sage300Command instance.
C#
string connectionString = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;"; using (Sage300Connection connection = new Sage300Connection(connectionString)) { Sage300Command cmd = new Sage300Command("EXECUTE APCreateGLBatch ProcessPaymentBatch = @ProcessPaymentBatch;", connection); cmd.Parameters.Add(new Sage300Parameter("@ProcessPaymentBatch", "DoNotPostPaymentBatches")); // Add other parameters as needed ... Sage300DataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { for (int i = 0; i < rdr.FieldCount; i++) { Console.WriteLine(rdr.GetName(i) + " --> " + rdr[i]); } Console.WriteLine(); } }
VB.NET
Dim connectionString As String = "User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;" Using connection As New Sage300Connection(connectionString) Dim cmd As New Sage300Command("EXECUTE APCreateGLBatch ProcessPaymentBatch = @ProcessPaymentBatch;", connection) cmd.Parameters.Add(New Sage300Parameter("@ProcessPaymentBatch", "DoNotPostPaymentBatches")) ' Add other parameters as needed ... Dim rdr As Sage300DataReader = cmd.ExecuteReader() While rdr.Read() For i As Integer = 0 To rdr.FieldCount - 1 Console.WriteLine(rdr.GetName(i) + " --> " + rdr(i)) Next Console.WriteLine() End While End Using