/    Sign up×
Community /Pin to ProfileBookmark

Error while calling a Procedure inside while loop

Hello everybody,

I have to call a procedure inside while loop.

But while doing this, it is working first time inside loop.

from second time onwards, it displays an error as,

“Procedure or function proc_User_Statistics has too many arguments specified”

I had called the procedure as follows.


———————————————

While objdrStatList.Read
TotalRec = objdrStatList(0)
CustomerCode = objdrStatList(1)
UserId = objdrStatList(2)
NetworkId = objdrStatList(3)
Dim TotalCredits = objdrStatList(4)

objUserStat.Connection = objcon1.objConnection
objUserStat.CommandType = CommandType.StoredProcedure
objUserStat.CommandText = “proc_User_Statistics”

objUserStat.Parameters.Add(“@StatDate”, SqlDbType.VarChar).Value = strDate
objUserStat.Parameters.Add(“@Records”, SqlDbType.Int).Value = TotalRec
objUserStat.Parameters.Add(“@CustomerCode”, SqlDbType.VarChar).Value = CustomerCode
objUserStat.Parameters.Add(“@UserId”, SqlDbType.VarChar).Value = UserId
objUserStat.Parameters.Add(“@NetworkId”, SqlDbType.VarChar).Value = NetworkId
objUserStat.Parameters.Add(“@TotalCredits”, SqlDbType.Int).Value = TotalCredits
objUserStat.ExecuteNonQuery()
objUserStat.Dispose()
objcon1.CloseConnection()

End While

objdrStatList.Close()
———————————————

Pls suggest me a solution. It is very urgent.

Thanks
Siva ([email protected])

to post a comment

5 Comments(s)

Copy linkTweet thisAlerts:
@PeOfEoJan 10.2005 — Well its just setting those same paramaters over and over it seems. It looks like you need to have a variable that increments in there somewhere.
Copy linkTweet thisAlerts:
@CstickJan 10.2005 — Replace this

objUserStat.Connection = objcon1.objConnection

objUserStat.CommandType = CommandType.StoredProcedure

objUserStat.CommandText = "proc_User_Statistics"

with this

objUserStat = new SQLCommand("proc_User_Statistics", Connection)

objUserStat.CommandType = CommandType.StoredProcedure

Basically, the same parameters are added each time it loops. Like 5,10,15,20,25,etc. So, the above re-instantiates the SQLCommand, which removes the previous parameters. Alternatively, there may be a method to clear the parameters from objUserStat.
Copy linkTweet thisAlerts:
@PeOfEoJan 10.2005 — I am having trouble just figureing out what is being accomplished with this loop!
Copy linkTweet thisAlerts:
@rskshivaauthorJan 10.2005 — Thanks. As of now, I am doing the looping inside the procedure itself.

Here i am just calling the procedure only one time with date as a parameter. If anyone found a good solution pls reply back.

Thanks,

Siva R
Copy linkTweet thisAlerts:
@dtchJan 10.2005 — The problem is that you are adding the parameters inside the loop. The first time of execution you have the right number of parameters, but on the second time your procedure gets double number of parameters.

Just put the lines where you add the parameters outside of the loop:

objUserStat.Parameters.Add("@StatDate", SqlDbType.VarChar)

And inside the loop assign only the value of the parameters:

objUserStat.Parameters.Item("@StatDate").Value = strDate


Do this for all of the parameters and you will be fine.

Good Luck!

By the way, having the loop inside the procedure works, but it is not a very good programming practice.
×

Success!

Help @rskshiva spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...