SQL Stored procedure to insert records from form

JohnMac328
JohnMac328 used Ask the Experts™
on
I am using CF to enter data from a form.  Can the same be done with a stored procedure?

Here is the coldfusion form

<cfquery name="AddVideo" datasource="#datasource#">
                INSERT INTO VideoList
                (CategoryID, Video_Name, Length, Production_Company, Credits, Availability, NumTests)
                VALUES (<cfqueryparam cfsqltype="CF_SQL_INteger"  value="#FORM.CategoryID#">,
                        <cfqueryparam cfsqltype="CF_SQL_VARCHAR"  value="#FORM.Video_Name#">,
                        <cfqueryparam cfsqltype="CF_SQL_VARCHAR"  value="#FORM.Length#">,
                        <cfqueryparam cfsqltype="CF_SQL_VARCHAR"  value="#FORM.Production_Company#">,
                        <cfqueryparam cfsqltype="CF_SQL_INteger"  value="#FORM.Credits#">,
                        <cfqueryparam cfsqltype="CF_SQL_INteger"  value="#FORM.Availability#">,
                         <cfqueryparam cfsqltype="CF_SQL_INteger"  value="#FORM.NumTests#">)
                       
        </cfquery>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
System Architect, CF programmer
Commented:
Yes it can. You would need to pass the parameters to the stored procedure , You will need to adjust the data types according to your database hierarchy

Call A stored procedure

<cfstoredproc procedure="spINSERT_dbo_VideoList " datasource="#request.datasource#">
	<cfprocparam value="#FORM.CategoryID#" cfsqltype="CF_SQL_INTEGER" type="In">
<cfprocparam value="#FORM.Video_Name#" cfsqltype="CF_SQL_VARCHAR " type="In">

and SO ON  .......


	<cfprocparam variable="isEmployeeReal" cfsqltype="CF_SQL_INTEGER" type="Out">
</cfstoredproc>

Open in new window


CREATE PROCEDURE dbo.spINSERT_dbo_VideoList @CategoryID int, @Video_Name varchar(250), 
@Length INT, @Production_Company varchar(255), @Credits int, @Availability bit,@NumTests INT
AS
SET NOCOUNT ON

INSERT INTO VideoList
           (CategoryID
           ,Video_Name 
           ,Length 
           ,Production_Company 
           ,Credits 
           ,Availability 
       ,NumTests 
)
     VALUES
           (@CategoryID 
           ,@Video_Name
           ,@Length 
           ,@Production_Company 
           ,@Credits 
           ,@Availability ,
           ,@NumTests 
)

Open in new window

Author

Commented:
Great - that does make sense now.

Author

Commented:
Great job

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial