Forums
This topic is locked
Stored procedures - insert using mult recordsets
Posted 25 Sep 2002 22:44:26
1
has voted
25 Sep 2002 22:44:26 dan gooner posted:
I know that this is possible, because it's so simple. Please!!! Someone help!!!I'm trying to create a SIMPLE form that posts information to my MS SQL Server database tables, via stored procedures. Basically, I have 2 stored procedures: One to create a recordset that will populate a dynamic drop-down menu with selection options (from Locations table); the other to insert records into a database table (Buildings).
The form should send back the integer number represented by the value selected in the Locations drop-down menu, together with the form field information input by the user, via the second stored procedure (ie the one to insert buildings).
I know that a bad workman always blames his tools, but DW won't let me execute any of this, as per the following messages:
1) when I try to create the recordset that'll bind to the form elements for the data entry fields:
[MS][ODBC - SQL Server Driver][SQL Server]
'usp_insert_new_building' expects parameter
'@locationID', which was not supplied.
###NB But the locationID IS supplied in the stored procedure and referenced in the field name, as far as I can see!####
2) when I try to launch the page in the browser (IE6):
Error Type:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub
/gfg/gfg_admin/add/TMP3yjem30feb.asp, line 60, column 54
cmdShowLocations.CreateParameter("RETURN_VALUE", 3, 4)
#### But DW created that line of code, NOT me!!!######
I've got 24 of these little forms to create, and I'm desperate to get one right so that I have the foundation for the others.
Can anyone help me? Pleeeeeeeeeeeease!!!
Sincere thank you in advance, if you can....
Regards
Toyin
The code I'm using is as follows:
Code for stored procedure BUILDINGS:
========================================
ALTER PROC usp_insert_new_building
-- declare all variables
(
@addbldg_name [varchar](50),
@addbldg_pic [varchar](100),
@addbldg_pic_caption [varchar](50),
@addbldg_map [varchar] (100),
@locationID [int]
)
AS
SET NOCOUNT ON
-- insert into Buildings table
INSERT INTO Buildings
(
bldg_name,
bldg_pic,
bldg_pic_caption,
bldg_map,
locationID
)
VALUES
(
@addbldg_name,
@addbldg_pic,
@addbldg_pic_caption,
@addbldg_map,
@locationID
)
SET NOCOUNT OFF
Go
Code for stored procedure LOCATIONS:
===========================================
ALTER PROCEDURE [usp_show_locations]
AS
SET NOCOUNT ON
SELECT locationID, location FROM [gfg].[dbo].[Locations]
WHERE
[location_expire] IS NULL AND [location] >0
ORDER BY
[location] ASC
SET NOCOUNT OFF
Go
ASP page that's doing my head in:
==============================================
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/gfg.asp" -->
<% If Request("Submit"

<%
Dim cmdAddBuildings__addbldg_name
cmdAddBuildings__addbldg_name = ""
if(Request("addbldg_name"


cmdAddBuildings__addbldg_name = Request("addbldg_name"

Dim cmdAddBuildings__addbldg_pic
cmdAddBuildings__addbldg_pic = ""
if(Request("addbldg_pic"


cmdAddBuildings__addbldg_pic = Request("addbldg_pic"

Dim cmdAddBuildings__addbldg_pic_caption
cmdAddBuildings__addbldg_pic_caption = ""
if(Request("addbldg_pic_caption"


cmdAddBuildings__addbldg_pic_caption = Request("addbldg_pic_caption"

Dim cmdAddBuildings__addbldg_map
cmdAddBuildings__addbldg_map = ""
if(Request("addbldg_map"


cmdAddBuildings__addbldg_map = Request("addbldg_map"

Dim cmdAddBuildings__locationID
cmdAddBuildings__locationID = ""
if(Request("locationID"


cmdAddBuildings__locationID = Request("locationID"

%>
<%
set cmdAddBuildings = Server.CreateObject("ADODB.Command"

cmdAddBuildings.ActiveConnection = MM_gfg_STRING
cmdAddBuildings.CommandText = "dbo.usp_insert_new_building"
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("RETURN_VALUE", 3,4)
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("@addbldg_name", 200,1,50,cmdAddBuildings__addbldg_name)
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("@addbldg_pic", 200,1,100,cmdAddBuildings__addbldg_pic)
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("@addbldg_pic_caption", 200,1,50,cmdAddBuildings__addbldg_pic_caption)
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("@addbldg_map", 200,1,100,cmdAddBuildings__addbldg_map)
cmdAddBuildings.Parameters.Append cmdAddBuildings.CreateParameter("@locationID", 3,1,4,cmdAddBuildings__locationID)
cmdAddBuildings.CommandType = 4
cmdAddBuildings.CommandTimeout = 0
cmdAddBuildings.Prepared = true
set rsAddBuildings = cmdAddBuildings.Execute
rsAddBuildings_numRows = 0
%>
<% End If %>
<%
set cmdShowLocations = Server.CreateObject("ADODB.Command"

cmdShowLocations.ActiveConnection = MM_gfg_STRING
cmdShowLocations.CommandText ="dbo.usp_show_locations_25sep"
cmdShowLocations.CommandType = 4
cmdShowLocations.CommandTimeout = 0
cmdShowLocations.Prepared = true
cmdShowLocations.Parameters.Append
cmdShowLocations.CreateParameter("RETURN_VALUE", 3, 4)
set rsDbShowLocations = cmdShowLocations.Execute
rsDbShowLocations_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
THIS IS A TEST FOR THE BULDINGS TABLE INSERT
<form action="Test.asp" method="post" name="formAddBuildings"
id="formAddBuildings">
<table width="681" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td><div align="right">bldg name</div></td>
<td><input name="addbldg_name" type="text"
id="addbldg_name"></td>
</tr>
<tr>
<td><div align="right">bldg_pic</div></td>
<td><input name="addbldg_pic" type="text"
id="addbldg_pic"></td>
</tr>
<tr>
<td><div
align="right">bldg_pic_caption</div></td>
<td><input name="addbldg_pic_caption"
type="text" id="addbldg_pic_caption"></td>
</tr>
<tr>
<td><div align="right">bldg_map</div></td>
<td><input name="addbldg_map" type="text"
id="addbldg_map"></td>
</tr>
<tr>
<td><div align="right">location</div></td>
<td><select name="locationID" id="locationID">
<%
While (NOT rsDbShowLocations.EOF)
%>
<option
value=" mmTranslatedValueHiliteColor="HILITECOLOR=%22Dyn%20Untranslated%20Color%22"<%=(rsDbShowLocations.Fields.Item("locationID"


<%
rsDbShowLocations.MoveNext()
Wend
If (rsDbShowLocations.CursorType > 0) Then
rsDbShowLocations.MoveFirst
Else
rsDbShowLocations.Requery
End If
%>
</select></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit" value="Submit">
<input name="Reset" type="submit" id="Reset"
value="Reset"></td>
</tr>
<tr>
<td height="19"> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>