Database Exchange > Using MS SQL Server 2000 as a Data Source > Changing the Parameters of a Stored Procedure at Runtime

Changing the Parameters of a Stored Procedure at Runtime

In the previous example, we use ('1996/07/01', '1996/07/21') as parameters. You might want to change parameters of a stored procedure to get different data at runtime. The Cicode example below shows you how to do this. Assume that the control occupies at “AN35” on the graphics page.

FUNCTION GetSelectedData(STRING sStartDate,STRING sEndDate)

STRING sParameters;

     sParameters ="('"+ sStartDate +"','"+ sEndDate +"')";

     _ObjectSetProperty(ObjectByName("AN35"), "StoredProcArgs",sParameters);

     _ObjectCallMethod(ObjectByName("AN35"), "Refresh");

END

To change the parameters of a stored procedure at runtime:

  1. Copy and paste the above function to your Cicode file.
  2. Create two memory string tags: DATE_1 and DATE_2.
  3. Add a button to the graphics page and enter the following code in the Input text box,

GetSelectedData(DATE_1, DATE_2)

  1. Add tags DATE_1 and DATE_2 on the page with display and input.
  2. Compile the project and run it. Enter values 1996/07/01 and 1996/07/11 to tags DATE_1 and DATE_2 respectively. Clicking the button produces these results:

Notes

  1. Use _ObjectSetProperty to set property "StoredProcArgs" to change parameters.
  2. Use _ObjectCallMethod to call method "Refresh" to refresh the linked data source.