473,804 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix "expects parameter" error

BRawn
28 New Member
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_PopulateMa nualSelectionFo rEdit' 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.Execute NonQuery() 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 1787
Christian Binder
218 Recognized Expert New Member
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 New Member
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 New Member
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
21643
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 server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
2
3902
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, and added the parameters to the SqlParametersCollection of the SqlCommand object. In the second, I just made it all into long execution string. I found that both executed with the same speed. I would claim that the second (shorter) method is...
4
1660
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 UploadData(ByVal sender As Object, ByVal e As EventArgs) Dim MyConn As New
14
3277
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 make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself which one to pass and which not, rather than relying on massively overlaoded methods which hopefully provide the best...
18
4364
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 can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
2
2633
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 to update a record, I get a "No value given for one or more parameters." error message. I use a Select with parameters and an Update with parameters. The select works fine. I thought I've tried everything (evidently not) to get this working. ...
12
2676
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 avoided. I'd like to hear your various opinions on this matter.
1
2511
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 SQLParameter() collection and trying to reference a particular parameter by name rather than index I get a Type Conversion error. But when declaring a SqlClient.SqlCommand object and then adding the parameters to the command object parameters...
0
2102
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 that can draw a rainbow, and each color of the rainbow can be turned on or off individually. My function specification can be of this form: “rainbow(red, orange, yellow, green, blue, violet, purple)”. Each parameter is a true or false value....
2
1738
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 ODBCDataReader Dim comm as New ODBCCommand("{call jgrant_awcconnect..edit_equipment (?, ?, ?, ?, ?, ?)}", conn) comm.parameters.add("@equipmentId", System.Data.SqlDbType.bigint) comm.parameters("@equipmentId").Direction = ParameterDirection.Input...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9157
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7621
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.