Skip navigation
Currently Being Moderated

running SQL or stored procedure from a button

Feb 13, 2013 6:12 AM

I would like to run SQL statement or a stored procedure from cfm file to run again MS SQL server.

I can have an OnClick event to have JavScript to execute the code.

I just wanted to know is it possible to run SQL statement or stored procedure from a button onClick event.

If not, can you please advise how to make this works?

 

Your help and informaiton is great appreciated,

 

Regards,

 

Iccsi,

 
Replies
  • Currently Being Moderated
    Feb 13, 2013 8:26 AM   in reply to iccsi

    Hi

     

    The simplest method is to set the form 'action' attribute to call the cfm-sql script when the form is submitted.

     

    Naturally this would require you to use JavaScript to set the required parameters and also check the parameters are correct, and ensure you are calling the correct sql statement/sp, if you are not doing so manually. This would be the same as calling a sql statement/sp when a form is submitted, (e.g. for a shopping carts 'update' quantity).

     

    PZ

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 13, 2013 10:38 AM   in reply to iccsi

    Hi

     

    You would use javascript to set the call to the sql statement/sp by its name. You could also use a drop-down list with all the statement/sp names to set this.

     

    Calling a statement is much easier that an sp, because the structure is much more forgiving to any errors, if a stored procedure is passed the incorrect info, or the info is not in the correct order, it will fail, and trying to find these types of errors is much more difficult in sp's. as sp's themselves are stored on the database server.

     

    PZ

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 13, 2013 1:13 PM   in reply to iccsi

    iccsi wrote:

     

    Any sample code I can look it?

    Hi

     

    Sample code would not help as it would not reflect your database tables, or how you would write the sql statement/stored-procedure.

     

    The simple way is to create a master/detail page with the statement/sp you require for this, then create the update statement/sp that would update the detail page with some information such as a discount for selecting more than one item when a button is clicked.

     

    Doing this should show you how to apply the statements/sp's and how they work when  a different statement/sp is used, (update for more than one item).

     

    PZ

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points