Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I reference web form fields in a stored procedure?

Status
Not open for further replies.

Qmoto

MIS
Oct 21, 2004
74
US
This is my first foray into stored procedures and I'm getting the following error:

Code:
[COLOR=red]Server: Msg 128, Level 15, State 1, Procedure MultiTableInsert, Line 23[/color]
The name 'req_id' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Here's the piece of the code causing the error:
INSERT INTO dbo.request_id (req_id, req_type, dep_name, ...)
  VALUES (req_id, req_type, dep_name, ...)

I've figured out why I'm getting the error...because the VALUES I'm trying to insert match the column names of the table I'm inserting into... but I havent figured out how to get the data from my form into the VALUES section of the code.

How do I reference that?
VALUES (form.texbox1.req_id)
VALUES (textbox1.req_id)
???
 
The form you are showing in your question is the correct one:

Code:
INSERT INTO dbo.request_id (req_id, req_type, dep_name, ...)
  VALUES (form.textbox1.req_id, ...)
 
You have to setup Input parameters in the Stored Procedure. Then when you call the SP from your app, you set values in the parameters then pass the parameters to your SP.

Since you are new, first look at how to set up parameters in a SP in Books On Line. (Create Procedure)

Jim
 
Thanks for the quick reply!

BugSlayer:
So am I correct in thinking that inserting a value from a radio button or a dropdown would be the same?

Code:
VALUES (form.radio1.req_id, form.select.req_type)

What about asp dropdowns?

jbenson001:
Thanks, I'll take a look at the Input Parameters. Can I set the parameter to a form variable? If so how?

Thanks again,
Steve
 
A VB.NET webpage, hopefully moving to php in the future.

 
If you are using a SQL Server stored procedure, you cannot use the syntax provided by TheBugSlayer. That looks like something in Access I think, but definately not SQL Server.
 
You have to create a stored procedure call in your webpage (ASP? PHP?) and pass the form variables into the SP. Google will give you pretty good results for tutorials for your scripting language of choice. Dreamweaver, etc will prompt you for all the parameters if you use their built in behaviours.

For example, asp:
4guysfromrolla and asp101 will have other examples.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top