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
Solved

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

Posted on 2004-10-12
8
393 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
 
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

791 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