473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Stored procedure error:

Hi, I am getting the error: "Procedure or function spAddActivity has too
many arguments specified. " on a stored procedure insert. I compared the
number of parameters in the function and the SP and they match. I compared
the type of the parameters and they match. I then made sure that everything
I wasn't inserting allowed nulls. The error persists. What else could
this be? Code and SP below. Its possible that I am stupid and missing the
obvious (due to give birth any minute and brain not quite as adept as
normal).

Thanks in advance!

Error: Procedure or function spAddActivity has too many arguments
specified.

Code:
Public Shared Function AddActivity(ByVal myActivity As Activity) As Integer

Dim conTA As New SqlConnection
Dim SInsert As String
Dim AddActSuccess As Boolean

conTA.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim cmdActivity As New SqlCommand
cmdActivity.CommandType = CommandType.StoredProcedure
cmdActivity.CommandText = "spAddActivity"
cmdActivity.Connection = conTA
cmdActivity.Parameters.Add("@orgid", myActivity.OrgID)
If myActivity.IndividualID = 0 Then
cmdActivity.Parameters.Add("@individualid", DBNull.Value)
Else
cmdActivity.Parameters.Add("@individualid", myActivity.IndividualID)
End If
cmdActivity.Parameters.Add("@apcauser", myActivity.APCAUser)
cmdActivity.Parameters.Add("@activitydescription",
myActivity.Description)cmdActivity.Parameters.Add( "@individualid",
myActivity.IndividualID)
If myActivity.ActivityDate = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@ActivityDate", DBNull.Value)
Else
cmdActivity.Parameters.Add("@ActivityDate", myActivity.ActivityDate)
End If
cmdActivity.Parameters.Add("@ta", myActivity.TA)
If myActivity.TypeTA = 0 Then
cmdActivity.Parameters.Add("@typeta", DBNull.Value)
Else
cmdActivity.Parameters.Add("@typeta", myActivity.TypeTA)
End If
If myActivity.EvalRequested = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@evalrequested", DBNull.Value)
Else
cmdActivity.Parameters.Add("@evalrequested", myActivity.EvalRequested)
End If
If myActivity.EvalCompleted = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@evalcompleted", DBNull.Value)
Else
cmdActivity.Parameters.Add("@evalcompleted", myActivity.EvalCompleted)
End If

If myActivity.TACategory = 0 Then
cmdActivity.Parameters.Add("@tacategory", DBNull.Value)
Else
cmdActivity.Parameters.Add("@tacategory", myActivity.TACategory)
End If
conTA.Open()
AddActSuccess = True
Try
cmdActivity.ExecuteNonQuery()
Catch ex As Exception
AddActSuccess = False
'End Try
conTA.Close()
Return AddActSuccess
End Function


Stored Procedure:
CREATE PROCEDURE spAddActivity

@orgid as integer,
@individualid as integer,
@apcauser as varchar(50),
@activitydescription as ntext,
@activitydate as datetime,
@TA as bit,
@typeTA as integer,
@evalrequested as datetime,
@evalcompleted as datetime,
@tacategory as integer

AS
begin transaction

insert into tblActivities
(org, person, [user], activitydescription, activitydate,
technicalassistance, typeta, evalrequested, evalcompleted, tacategory)
values
(@orgid, @individualid, @apcauser, @activitydescription, @activitydate,
@TA, @typeTA, @evalrequested, @evalcompleted, @tacategory)

If @@Error <> 0
BEGIN
ROLLBACK TRAN
RETURN

END
COMMIT TRANSACTION
GO
Nov 19 '05 #1
1 1360
Hi Child,

You've added "@individualid" twice. First, conditionally, second
unconditionally:
If myActivity.IndividualID = 0 Then
cmdActivity.Parameters.Add("@individualid", DBNull.Value)
Else
cmdActivity.Parameters.Add("@individualid", myActivity.IndividualID)
End If
....
myActivity.Description)cmdActivity.Parameters.Add( "@individualid",
myActivity.IndividualID)
An easy mistake to make, and a hard one to find, so don't be hard on
yourself.

BTW, here's how I found it (and it wasn't easy!):

First, I counted the number of parameters in your SP. Then I counted the
number of additions of parameters in your code. In the query I came up with
10, after counting a couple of times to make sure. In the code, which was a
bit harder due to the conditional statements, I counted 11. I then had to
read through the code several times to find the duplicate (which, because it
was a duplicate, was rather hard to identify).

One way to avoid this in the future would be to put the addition of the
parameters in your code in the same order as the parameter list in the
query. You came close, but the order was a bit mixed up near the beginning.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Child" <Sp**********@alaska.com> wrote in message
news:11*************@corp.supernews.com... Hi, I am getting the error: "Procedure or function spAddActivity has too
many arguments specified. " on a stored procedure insert. I compared the
number of parameters in the function and the SP and they match. I
compared the type of the parameters and they match. I then made sure that
everything I wasn't inserting allowed nulls. The error persists. What
else could this be? Code and SP below. Its possible that I am stupid
and missing the obvious (due to give birth any minute and brain not quite
as adept as normal).

Thanks in advance!

Error: Procedure or function spAddActivity has too many arguments
specified.

Code:
Public Shared Function AddActivity(ByVal myActivity As Activity) As
Integer

Dim conTA As New SqlConnection
Dim SInsert As String
Dim AddActSuccess As Boolean

conTA.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionStrin g")
Dim cmdActivity As New SqlCommand
cmdActivity.CommandType = CommandType.StoredProcedure
cmdActivity.CommandText = "spAddActivity"
cmdActivity.Connection = conTA
cmdActivity.Parameters.Add("@orgid", myActivity.OrgID)
If myActivity.IndividualID = 0 Then
cmdActivity.Parameters.Add("@individualid", DBNull.Value)
Else
cmdActivity.Parameters.Add("@individualid", myActivity.IndividualID)
End If
cmdActivity.Parameters.Add("@apcauser", myActivity.APCAUser)
cmdActivity.Parameters.Add("@activitydescription",
myActivity.Description)cmdActivity.Parameters.Add( "@individualid",
myActivity.IndividualID)
If myActivity.ActivityDate = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@ActivityDate", DBNull.Value)
Else
cmdActivity.Parameters.Add("@ActivityDate", myActivity.ActivityDate)
End If
cmdActivity.Parameters.Add("@ta", myActivity.TA)
If myActivity.TypeTA = 0 Then
cmdActivity.Parameters.Add("@typeta", DBNull.Value)
Else
cmdActivity.Parameters.Add("@typeta", myActivity.TypeTA)
End If
If myActivity.EvalRequested = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@evalrequested", DBNull.Value)
Else
cmdActivity.Parameters.Add("@evalrequested", myActivity.EvalRequested)
End If
If myActivity.EvalCompleted = DateTime.MaxValue Then
cmdActivity.Parameters.Add("@evalcompleted", DBNull.Value)
Else
cmdActivity.Parameters.Add("@evalcompleted", myActivity.EvalCompleted)
End If

If myActivity.TACategory = 0 Then
cmdActivity.Parameters.Add("@tacategory", DBNull.Value)
Else
cmdActivity.Parameters.Add("@tacategory", myActivity.TACategory)
End If
conTA.Open()
AddActSuccess = True
Try
cmdActivity.ExecuteNonQuery()
Catch ex As Exception
AddActSuccess = False
'End Try
conTA.Close()
Return AddActSuccess
End Function


Stored Procedure:
CREATE PROCEDURE spAddActivity

@orgid as integer,
@individualid as integer,
@apcauser as varchar(50),
@activitydescription as ntext,
@activitydate as datetime,
@TA as bit,
@typeTA as integer,
@evalrequested as datetime,
@evalcompleted as datetime,
@tacategory as integer

AS
begin transaction

insert into tblActivities
(org, person, [user], activitydescription, activitydate,
technicalassistance, typeta, evalrequested, evalcompleted, tacategory)
values
(@orgid, @individualid, @apcauser, @activitydescription, @activitydate,
@TA, @typeTA, @evalrequested, @evalcompleted, @tacategory)

If @@Error <> 0
BEGIN
ROLLBACK TRAN
RETURN

END
COMMIT TRANSACTION
GO

Nov 19 '05 #2

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

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
0
by: Rhino | last post by:
I've written several Java stored procedures now (DB2 V7.2) and I'd like to write down a few "best practices" for reference so that I will have them handy for future development. Would the...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
7
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored...
4
by: barmatt80 | last post by:
I am stumped on the error reporting with sql server. I was told i need to return @SQLCode(code showing if successful or not) and @ErrMsg(and the message returned). I am clueless on this. I...
0
by: SOI_0152 | last post by:
Hi all! Happy New Year 2008. Il hope it will bring you love and happyness I'm new on this forum. I wrote a stored procedure on mainframe using DB2 7.1.1 and IBM language c. Everything works...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.