Solved

Running a stored procedure from VB.Net with parameters - expecting parameter

Posted on 2004-10-12
8
369 Views
Last Modified: 2012-08-14
I know that there is just a little thing missing, but I am unable to see it. Here is the error message that I receive:

Procedure 'sp_jrn_SelectDivStrategyIDByDivStrategyCode' expects parameter '@DivisionID' which was not supplied.

Original VB.Net code
'define a new data adapter
            Dim daStrategy As SqlClient.SqlDataAdapter

           'using the new data adapter locate in the database table tblDivStrategy any records with the same strategy code
            daStrategy = New SqlClient.SqlDataAdapter("sp_jrn_SelectDivStrategyIDByDivStrategyCode", conn)
            With daStrategy
                .SelectCommand.CommandType = CommandType.StoredProcedure
                .SelectCommand.Parameters.Add(New SqlClient.SqlParameter("@DivStrategyCode", SqlDbType.Decimal))
                .SelectCommand.Parameters.Add(New SqlClient.SqlParameter("@DivisionID", SqlDbType.Int))
                .SelectCommand.Parameters("@DivStrategyCode").Value = txtStrategyCode.ClipText
                .SelectCommand.Parameters("@DivisionID").Value = drDivision("DivisionID")
            End With
           
            'fill the data set's (dsOther9) table Strategy with the data from the above select query
            daStrategy.Fill(dsOther9, "Strategy")

Stored procedure:
CREATE PROCEDURE [dbo].[sp_jrn_SelectDivStrategyIDByDivStrategyCode] (@DivStrategyCode Decimal, @DivisionID Integer)
AS
SELECT DivStrategyID
FROM vw_DivisionStrategyDetails
WHERE DivisionID = @DivisionID AND DivStrategy_Code = @DivStrategyCode
GO

Now, if I change the stored procedure to read as (only showing the WHERE line, no other changes)
         WHERE DivisionID = @DivisionID
it works as I expect it to work.

I have confirmed variable names, the variables contain data etc. I think I just need another set of eyes to look at my code, I do similar things in other places and it works.

Thanks Experts!!
0
Comment
Question by:MajikTara
8 Comments
 
LVL 10

Assisted Solution

by:Hans Langer
Hans Langer earned 100 total points
ID: 12293275
Its a web app ?
Recompile :P
0
 
LVL 7

Accepted Solution

by:
ramesh12 earned 100 total points
ID: 12293507
check to make sure that you have values in here  drDivision("DivisionID")

i.e drDivision("DivisionID") is not null
0
 
LVL 14

Assisted Solution

by:ptakja
ptakja earned 100 total points
ID: 12294149
Since your DivStrategyCode is defined as a Decimal, try coverting the textbox "Text" to a Decimal. The issue could be that you are passing a "string" into the Decimal parameter.

   .SelectCommand.Parameters("@DivStrategyCode").Value = Convert.ToDecimal(txtStrategyCode.ClipText)
0
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 100 total points
ID: 12294461
How are you getting the value of "drDivision("DivisionID")" ?
-Baan
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Assisted Solution

by:etmendz
etmendz earned 100 total points
ID: 12296568
You've checked the variables names... What about the field name DivStrategy_Code? Is that correct?

Have fun...
0
 

Author Comment

by:MajikTara
ID: 12298446
Gerente - No, this is not a web app. It is a windows app.

ramesh12 - I ran a messagebox that showed that the value drDivision("DivisionID") is a integer.

ptakja - Prior to changing the code to include the "@DivisionID" the code was only for "@DivStrategycode" and was working fine. I added the "@DivisionID" code for a different filter process in the SQL code.

DotNetLover Baan - the value of drDivision("DivisionID") is from a dataset (in memory) that is created then assigned to a datarow. The value of drDivision("DivisionID") is an integer.

etmendz - Yes, I reviewed all the variable names, even copied them from their source.

All - I believe it is just a syntax error that I am not seeing. Any other suggestions?
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12298674
I cant see errors in the systaxis.

Maybe the app is not compiling well,
Restart Windows, Restart  VS.NET, check Read-only files property,
Maybe something is blocked.
0
 

Author Comment

by:MajikTara
ID: 12299378
All -
It was a combination of your answers that helped me find the problem - I used the same stored procedure later but I did not update my VB code to reflect the change of adding the field "@DivisionID".  

Thanks All,

MT
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now