473,769 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP / Stored Procedure SQL Insert Help

Hi there - this should be fairly simple for someone. Basically I
can't figure out how to pass the parameters from ASP to a Stored
Procedure on SQL.

Here's my code:

I just need to help in learning how to pass these varibables from ASP
to the SP.
Here's my ASP code ...
*************** *************** *************** *************** *********
DIM Connect, Q, AdminRep, LTSOffice, Gender, OfficeNum

AdminRep = Request("AdminR ep")
LTSOffice = Request("LTSOff ice")
Gender = Request("Gender ")
OfficeNum = Request.Cookies ("OfficeNum" )

SET Connect = SERVER.CREATEOB JECT("ADODB.CON NECTION")
Connect.Open = "DATABASE=blah; UID=blah;PWD=bl ah;DSN=blah;"
Connect.Execute ("Insert_LeadSt at")
Connect.Close
Set Connect = Nothing
*************** *************** *************** *************** *********
Gives me this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
'insert_LeadSta t' expects parameter '@OfficeNum', which was not
supplied.
/ltsenroll/leadsource_dbad d.asp, line 22

Here's my Stored procedure ...
*************** *************** *************** *************** *********
CREATE PROCEDURE [insert_LeadStat]
( @OfficeNum [int],
@LTSOffice [varchar](50),
@AdminRep [varchar](50),)
AS INSERT INTO [MFKProductions].[dbo].[LeadStats]
( [OfficeNum],
[LTSOffice],
[AdminRep],)
VALUES
( @OfficeNum,
@LTSOffice,
@AdminRep,)
GO

I've searched through the groups and thought I had it with
"parameters.app end .createparamete r ...." but I can't seem to get this
to work ...

Thanks in advance
Jul 19 '05 #1
7 9011
Set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open ...

Set objCommand = Server.CreateOb ject("ADODB.Com mand")
Set objCommand.Acti veConnection = objConn
With objCommand
.CommandType = adCmdStoredProc
.CommandText = Insert_LeadStat "
.Parameters.App end .CreateParamete r("@OfficeNum ", adInteger,
adParamInput, 4, OfficeNum)
'
' Append other parameters here
'
.Execute
End With

Set objCommand = Nothing
objConn.Close
Set objConn = Nothing

Cheers
Ken

"Bill Kellaway" <bi**********@h otmail.com> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
: Hi there - this should be fairly simple for someone. Basically I
: can't figure out how to pass the parameters from ASP to a Stored
: Procedure on SQL.
:
: Here's my code:
:
: I just need to help in learning how to pass these varibables from ASP
: to the SP.
:
:
: Here's my ASP code ...
: *************** *************** *************** *************** *********
: DIM Connect, Q, AdminRep, LTSOffice, Gender, OfficeNum
:
: AdminRep = Request("AdminR ep")
: LTSOffice = Request("LTSOff ice")
: Gender = Request("Gender ")
: OfficeNum = Request.Cookies ("OfficeNum" )
:
: SET Connect = SERVER.CREATEOB JECT("ADODB.CON NECTION")
: Connect.Open = "DATABASE=blah; UID=blah;PWD=bl ah;DSN=blah;"
: Connect.Execute ("Insert_LeadSt at")
: Connect.Close
: Set Connect = Nothing
: *************** *************** *************** *************** *********
: Gives me this error:
: Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
: [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
: 'insert_LeadSta t' expects parameter '@OfficeNum', which was not
: supplied.
: /ltsenroll/leadsource_dbad d.asp, line 22
:
: Here's my Stored procedure ...
: *************** *************** *************** *************** *********
: CREATE PROCEDURE [insert_LeadStat]
: ( @OfficeNum [int],
: @LTSOffice [varchar](50),
: @AdminRep [varchar](50),)
: AS INSERT INTO [MFKProductions].[dbo].[LeadStats]
: ( [OfficeNum],
: [LTSOffice],
: [AdminRep],)
: VALUES
: ( @OfficeNum,
: @LTSOffice,
: @AdminRep,)
: GO
:
: I've searched through the groups and thought I had it with
: "parameters.app end .createparamete r ...." but I can't seem to get this
: to work ...
:
: Thanks in advance
Jul 19 '05 #2
Ken's given you a good answer, I just wanted to add:
Bill Kellaway wrote:
Connect.Open = "DATABASE=blah; UID=blah;PWD=bl ah;DSN=blah;"
You should be using the native OLEDB provider for SQL: the ODBC provider has
been deprecated by Microsoft. See www.connectionstrings.com

Connect.Execute ("Insert_LeadSt at")
Connect.Close
Set Connect = Nothing
*************** *************** *************** *************** *********
Gives me this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
'insert_LeadSta t' expects parameter '@OfficeNum', which was not
supplied.
/ltsenroll/leadsource_dbad d.asp, line 22
You did not pass any parameters.

Here's my Stored procedure ...
*************** *************** *************** *************** *********
CREATE PROCEDURE [insert_LeadStat]
( @OfficeNum [int],
@LTSOffice [varchar](50),
@AdminRep [varchar](50),)
AS INSERT INTO [MFKProductions].[dbo].[LeadStats]
( [OfficeNum],
[LTSOffice],
[AdminRep],)
VALUES
( @OfficeNum,
@LTSOffice,
@AdminRep,)
GO

If you want to use a Command object to run this procedure, you may want to
give my free Stored Procedure Call Code Generator a try. It's available at
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear

However, your procedure has no ouptut parameters and you do not seem to be
interested in the Return parameter, so you do not need a Command object: you
can use the stored-procedure-as-connection-method technique:

dim offnum, lts, admin
offnum = ...
lts = "..."
admin = "..."
Connect.insert_ LeadStat offnum, lts,admin

Pass the parameter values just as if insert_LeadStat was a native method of
your connection object. Use variables or literal values.

HTH,
Bob Barrows


Jul 19 '05 #3
Thanks Ken !!! works great ..

Took me a bit .. had to include ADOVBS and then took awhile to the the
correct verbiage for adVarchars ...

Thanks again ...

"Ken Schaefer" <ke*******@THIS adOpenStatic.co m> wrote in message
news:e5******** ******@TK2MSFTN GP10.phx.gbl...
Set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open ...

Set objCommand = Server.CreateOb ject("ADODB.Com mand")
Set objCommand.Acti veConnection = objConn
With objCommand
.CommandType = adCmdStoredProc
.CommandText = Insert_LeadStat "
.Parameters.App end .CreateParamete r("@OfficeNum ", adInteger,
adParamInput, 4, OfficeNum)
'
' Append other parameters here
'
.Execute
End With

Set objCommand = Nothing
objConn.Close
Set objConn = Nothing

Cheers
Ken

"Bill Kellaway" <bi**********@h otmail.com> wrote in message
news:f3******** *************** ***@posting.goo gle.com...
: Hi there - this should be fairly simple for someone. Basically I
: can't figure out how to pass the parameters from ASP to a Stored
: Procedure on SQL.
:
: Here's my code:
:
: I just need to help in learning how to pass these varibables from ASP
: to the SP.
:
:
: Here's my ASP code ...
: *************** *************** *************** *************** *********
: DIM Connect, Q, AdminRep, LTSOffice, Gender, OfficeNum
:
: AdminRep = Request("AdminR ep")
: LTSOffice = Request("LTSOff ice")
: Gender = Request("Gender ")
: OfficeNum = Request.Cookies ("OfficeNum" )
:
: SET Connect = SERVER.CREATEOB JECT("ADODB.CON NECTION")
: Connect.Open = "DATABASE=blah; UID=blah;PWD=bl ah;DSN=blah;"
: Connect.Execute ("Insert_LeadSt at")
: Connect.Close
: Set Connect = Nothing
: *************** *************** *************** *************** *********
: Gives me this error:
: Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
: [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
: 'insert_LeadSta t' expects parameter '@OfficeNum', which was not
: supplied.
: /ltsenroll/leadsource_dbad d.asp, line 22
:
: Here's my Stored procedure ...
: *************** *************** *************** *************** *********
: CREATE PROCEDURE [insert_LeadStat]
: ( @OfficeNum [int],
: @LTSOffice [varchar](50),
: @AdminRep [varchar](50),)
: AS INSERT INTO [MFKProductions].[dbo].[LeadStats]
: ( [OfficeNum],
: [LTSOffice],
: [AdminRep],)
: VALUES
: ( @OfficeNum,
: @LTSOffice,
: @AdminRep,)
: GO
:
: I've searched through the groups and thought I had it with
: "parameters.app end .createparamete r ...." but I can't seem to get this
: to work ...
:
: Thanks in advance

Jul 19 '05 #4
Bill Kellaway wrote:
Thanks Ken !!! works great ..

Took me a bit .. had to include ADOVBS


http://www.aspfaq.com/show.asp?id=2112

Just to make sure you did not miss this:

If you want to use a Command object to run this procedure, you may want to
give my free Stored Procedure Call Code Generator a try. It's available at
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear

However, your procedure has no ouptut parameters and you do not seem to be
interested in the Return parameter, so you do not need a Command object: you
can use the stored-procedure-as-connection-method technique:

dim offnum, lts, admin
offnum = ...
lts = "..."
admin = "..."
Connect.insert_ LeadStat offnum, lts,admin

Pass the parameter values just as if insert_LeadStat was a native method of
your connection object. Use variables or literal values.

HTH,
Bob Barrows
Jul 19 '05 #5
Thanks Bob,

I'm not sure what the Return Parameter does. I'll take a guess though -
please correct me if I'm wrong - It's SQL's way of telling the Command
object if the command was successful or not ??? If so, this would be very
helpful to me. The reason that I changed this page from ADO to a SP Insert
was that I was getting intermittant duplicate inserts. Rebooting SQL
seemed to help for awhile.

Might I be able to use a return parameter to prevent duplicate inserts from
the ASP page ???

Thanks again all ...

Bill

"Bob Barrows" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Bill Kellaway wrote:
Thanks Ken !!! works great ..

Took me a bit .. had to include ADOVBS
http://www.aspfaq.com/show.asp?id=2112

Just to make sure you did not miss this:

If you want to use a Command object to run this procedure, you may want to
give my free Stored Procedure Call Code Generator a try. It's available at

http://www.thrasherwebdesign.com/ind...asp&c=&a=clear
However, your procedure has no ouptut parameters and you do not seem to be
interested in the Return parameter, so you do not need a Command object: you can use the stored-procedure-as-connection-method technique:

dim offnum, lts, admin
offnum = ...
lts = "..."
admin = "..."
Connect.insert_ LeadStat offnum, lts,admin

Pass the parameter values just as if insert_LeadStat was a native method of your connection object. Use variables or literal values.

HTH,
Bob Barrows

Jul 19 '05 #6
Bill Kellaway wrote:
Thanks Bob,

I'm not sure what the Return Parameter does. I'll take a guess
though - please correct me if I'm wrong - It's SQL's way of telling
the Command object if the command was successful or not ???
Close. The Return parameter contains the value returned by a RETURN
statement in your SP. If you do not have a RETURN statement, a successful
procedure will return 0, while a procedure that raises an error will return
NULL.

There are 3 ways to return values from a SQL Server stored procedure:
1. a Select statement that returns a resultset
--run this script in Query Analyzer (QA):
Create Procedure SelectValue
(@input int)
AS
Select @input + 5
go
exec SelectValue 10
go
drop procedure SelectValue
2. a Return parameter:
--run this script in QA:
create procedure ReturnValue
(@input int)
AS
Return @input + 5
go
declare @returnvalue int
exec @returnvalue = ReturnValue 10
select @returnvalue
go
drop procedure ReturnValue

3. an Output Parameter:
--run this script in QA:
create procedure OutputValue
(@input int output)
AS
SET @input = @input + 5
go
declare @outputvalue int
SET @outputvalue = 10
exec OutputValue @outputvalue output
select @outputvalue
go
drop procedure OutputValue
I do not recommend method 1 for returning a single value. A resultset is
expensive to build, in that it must contain metadata in addition to data. So
more network traffic is created, and the client app needs to expend more
resources in order to retrieve and expose the resultset to the calling
procedure.

Most developers use the Return parameter to return status codes instead of
data. This is for the sake of consistency: there is no technical reason not
to use RETURN to return data, except that RETURN can only be used to return
integers. If you need to return other datatypes, you need to use an output
parameter.
If so,
this would be very helpful to me. The reason that I changed this
page from ADO to a SP Insert was that I was getting intermittant
duplicate inserts. Rebooting SQL seemed to help for awhile.

Very strange. Did you have a unique index to prevent duplicate inserts?
Might I be able to use a return parameter to prevent duplicate
inserts from the ASP page ???


Yes, but you don't have to. You can use EXISTS in your stored procedure to
do this without raising an error:

IF NOT EXISTS
(Select * from sometable
where somecolumn=<dat a_to_be_inserte d>)
BEGIN
INSERT sometable ...
END
--optionally - do this only if you want your client app to know
ELSE
BEGIN
RETURN 2
--code which you create to designate that record exists
END

HTH,
Bob Barrows
Jul 19 '05 #7

"Bob Barrows" <re******@NOyah oo.SPAMcom> wrote in message
news:eH******** ******@TK2MSFTN GP12.phx.gbl...
Bill Kellaway wrote:
Thanks Bob,

I'm not sure what the Return Parameter does. I'll take a guess
though - please correct me if I'm wrong - It's SQL's way of telling
the Command object if the command was successful or not ???


Ah .. of course ... a select statement would have to have return values
.... not required with an Insert ...

So .. how might I access this return value of 0 from ASP ?

Also .. no .. I have no index's on that table. This table used to count
phone calls. If you were to index that table what field would you index ?

Thanks again for your great help ...

Bill
Close. The Return parameter contains the value returned by a RETURN
statement in your SP. If you do not have a RETURN statement, a successful
procedure will return 0, while a procedure that raises an error will return NULL.

There are 3 ways to return values from a SQL Server stored procedure:
1. a Select statement that returns a resultset
--run this script in Query Analyzer (QA):
Create Procedure SelectValue
(@input int)
AS
Select @input + 5
go
exec SelectValue 10
go
drop procedure SelectValue
2. a Return parameter:
--run this script in QA:
create procedure ReturnValue
(@input int)
AS
Return @input + 5
go
declare @returnvalue int
exec @returnvalue = ReturnValue 10
select @returnvalue
go
drop procedure ReturnValue

3. an Output Parameter:
--run this script in QA:
create procedure OutputValue
(@input int output)
AS
SET @input = @input + 5
go
declare @outputvalue int
SET @outputvalue = 10
exec OutputValue @outputvalue output
select @outputvalue
go
drop procedure OutputValue
I do not recommend method 1 for returning a single value. A resultset is
expensive to build, in that it must contain metadata in addition to data. So more network traffic is created, and the client app needs to expend more
resources in order to retrieve and expose the resultset to the calling
procedure.

Most developers use the Return parameter to return status codes instead of
data. This is for the sake of consistency: there is no technical reason not to use RETURN to return data, except that RETURN can only be used to return integers. If you need to return other datatypes, you need to use an output
parameter.
If so,
this would be very helpful to me. The reason that I changed this
page from ADO to a SP Insert was that I was getting intermittant
duplicate inserts. Rebooting SQL seemed to help for awhile.


Very strange. Did you have a unique index to prevent duplicate inserts?
Might I be able to use a return parameter to prevent duplicate
inserts from the ASP page ???


Yes, but you don't have to. You can use EXISTS in your stored procedure to
do this without raising an error:

IF NOT EXISTS
(Select * from sometable
where somecolumn=<dat a_to_be_inserte d>)
BEGIN
INSERT sometable ...
END
--optionally - do this only if you want your client app to know
ELSE
BEGIN
RETURN 2
--code which you create to designate that record exists
END

HTH,
Bob Barrows

Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6587
by: Jarrod Morrison | last post by:
Hi all Im relatively new to using stored procedures and im not sure if it is possible to do what I am trying to do so any help here is greatly appreciated. I am using the variable @MachineName which is obviously the local machine name mainly in this procedure. What is loop through from the first character of the variable to the last and use this data in a select statement. I have included the code below for what I have tried so far but I...
4
13468
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will not work. I've been trying to get this to work with converting the UDF to a procedure, but I'm having no luck. Here is the background on what I'm trying to accomplish. I need to perform a sub-identity on a table, I have the normal identity set,...
6
2361
by: SandySears | last post by:
I am trying to use a stored procedure to insert a record using VS 2005, VB and SQL Server Express. The code runs without errors or exceptions, and returns the new identifer in the output parameters. It returns my error text message in another output parameter as "ok", which is the value that is set in the stored procedure prior to doing the insert. It returns my var for @@rowcount as 1. However, the record does not get into the table. ...
10
2942
by: J. S. EDV | last post by:
Hello, I have got a little problem with stored procedures and C#. I have got a stored procedure which should only insert something in a table. For example: ALTER PROCEDURE DBO.PROC1 AS insert into dbo.Test values ('test')
4
4361
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier Architecture. The Stored Procedures are used through TableAdaptors, which in turn are used by Class Files. I wish to be able to return this new ID value using the Stored
9
2468
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
17
4013
by: Riaaaa | last post by:
Pls check my code for the stored procedure which i created for the companydetails including companyid P.K. Not Null int(4), companyname Not Null varchar (20), address varchar(30) where companyid is the primary key and it should be autogenerate.
1
6134
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
0
864
by: Riaaaa | last post by:
Hi frdz, I have created the form for entering the company details with its general information in asp.net C# 2005. I want to put the validation that the user cannot enter the same name of company's twice with the different id's. I have created the stored procedure for the insert and update : The following is the insert stored procedure created in the SQL SERVER 2005.
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.