?
Solved

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

Posted on 2004-10-12
8
Medium Priority
?
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 10

Assisted Solution

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

Accepted Solution

by:
ramesh12 earned 300 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 300 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 300 total points
ID: 12294461
How are you getting the value of "drDivision("DivisionID")" ?
-Baan
0
 
LVL 6

Assisted Solution

by:etmendz
etmendz earned 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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