473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to fix "expects parameter" error

BRawn
28
Hi,

I'm writing an application which needs SQL parameters to be passed, and even though I've assigned parameters to the stored procedure, I keep getting the following error message from the debugger:

'usp_PopulateManualSelectionForEdit' expects parameter '@BinID', which was not supplied.

The stored proc:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE usp_PopulateManualSelectionForEdit
  2.  
  3.     @BinID int,
  4.     @ProductID int,
  5.     @ToteID int,
  6.     @PickAmount int
  7.  
  8. AS
  9.  
  10. SELECT
  11.     c.CON_ID,
  12.     c.CON_DESC,
  13.     p.PROD_ID,
  14.     p.PROD_NAME,
  15.     pic.PICKINSTRLINE_ID,
  16.     pic.PICKINSTRLINE_QTY_NEEDED,
  17.     t.TOTE_ID,
  18.     t.TOTE_NR
  19. FROM TBLCONTAINERS c
  20.     INNER JOIN TBLPRODUCT p WITH(NOLOCK) ON p.PROD_ID = c.PROD_ID
  21.     INNER JOIN TBLPICKINSTRLINES pic WITH(NOLOCK) ON pic.CON_ID = c.CON_ID
  22.     INNER JOIN TBLTOTES t WITH(NOLOCK) ON t.TOTE_ID = pic.TOTE_ID
  23. WHERE c.CON_ID = @BinID
  24. AND c.CON_ACTIVE = 1
  25. AND p.PROD_ID = @ProductID
  26. AND p.PROD_ACTIVE = 1
  27. AND t.TOTE_ID = @ToteID
  28. AND t.TOTE_ACTIVE = 1
  29. AND pic.PICKINSTRLINE_QTY_NEEDED = @PickAmount
  30.  
The stored proc executes fine in SQL when I give the parameters values, so it can't be an incorrect script.

The code-behind (C#):

Expand|Select|Wrap|Line Numbers
  1. public DataSet populateManualSelectionForEdit(DataSet dataSet, int binID, int productID, int toteID, int pickAmount)
  2.         {
  3.             using (SqlConnection connection = InstancesTest.IDataInterface.DefineConnection())
  4.             {
  5.                 SqlCommand command = new SqlCommand();
  6.                 command.CommandType = CommandType.StoredProcedure;
  7.                 command.CommandText = "usp_PopulateManualSelectionForEdit";
  8.                 command.Connection = connection;
  9.  
  10.                 try
  11.                 {
  12.                     if (connection.State == ConnectionState.Closed)
  13.                     {
  14.                         connection.Open();
  15.                     }
  16.  
  17.                     command.Parameters.Add("@BinID", SqlDbType.Int);
  18.                     command.Parameters["@BinID"].Value = binID;
  19.                     command.Parameters.Add("@ProductID", SqlDbType.Int);
  20.                     command.Parameters["@ProductID"].Value = productID;
  21.                     command.Parameters.Add("@ToteID", SqlDbType.Int);
  22.                     command.Parameters["@ToteID"].Value = toteID;
  23.                     command.Parameters.Add("@PickAmount", SqlDbType.Int);
  24.                     command.Parameters["@PickAmount"].Value = pickAmount;
  25.  
  26.                     command.ExecuteNonQuery();
  27.  
  28.                     SqlDataAdapter da = new SqlDataAdapter(command.CommandText, connection);
  29.                     da.Fill(dataSet);
  30.                 }
  31.                 catch (Exception ex)
  32.                 {
  33.                     MessageBox.Show(ex.ToString(), "Error in Stored Procedure");
  34.                 }
  35.                 finally
  36.                 {
  37.                     if (connection.State == ConnectionState.Open)
  38.                     {
  39.                         connection.Close();
  40.                     }
  41.                 }
  42.                 return dataSet;
  43.             }
  44.         }
  45.  

As you can see, I'm giving the parameters their values, but they're not getting passed to the stored proc. I initially left the command.ExecuteNonQuery() method out of the logic, but that didn't work either. I'm not too sure whether or not I should use a DataReader.
I don't want my query in a string in C#, so please don't suggest someting like selectQuery = "SELECT * FROM TBLPROJECTS";
Any other suggestions to a work-around would be appreciated.

Thanks,
BRawn
Jul 13 '10 #1
3 1771
Christian Binder
218 Expert 100+
On line 28 you do
Expand|Select|Wrap|Line Numbers
  1. SqlDataAdapter da = new SqlDataAdapter(command.CommandText, connection);
  2.  
So just the CommandText will be executed (without parameters)

You could do it like that:
Expand|Select|Wrap|Line Numbers
  1. SqlDataReader dr = command.ExecuteReader();
  2. System.Data.DataSet ds = new System.Data.DataSet();
  3. System.Data.DataTable dt = new System.Data.DataTable("table");
  4. dt.Load(dr);
  5. ds.Tables.Add(dt);
  6.  
Jul 13 '10 #2
BRawn
28
Thanks a lot, seems to have worked and what you said makes sense..."The CommandText will be executed (without parameters)"
Jul 13 '10 #3
broger
2
You could also default your SQL input parameters:

@BinID int DEFAULT -1

Or something like that
Jul 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
2
by: Mark | last post by:
I created a test to check the execution time difference between executing a SQL Server stored procedured using explicit parameters versus not. In one case I created new SqlParameters in the code,...
4
by: Tim::.. | last post by:
Can someone tell me a better way or give me a link that shows a better way to create large numbers of SQL parameters... Example... A better way to write this code! <code> Sub...
14
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
12
by: pamelafluente | last post by:
Hi guys, In the past I have used several time optional parameters in my function. But Now I am more inclined to think that they are more dangerous than useful, and probably better to be...
1
by: John Kotuby | last post by:
Hi all, I am working on porting an application from VB6 to VB.NET 2003 and am running into some problems. When declaring and populating the parameters for a SQL Stored Procedure by using the...
0
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
2
by: Jared Grant | last post by:
I am trying to find the value from some output parameters from a stored procedure. I have tried several different methods but somehow cannot get it to work. here is my source code: dim dr as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.