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: -
CREATE PROCEDURE usp_PopulateManualSelectionForEdit
-
-
@BinID int,
-
@ProductID int,
-
@ToteID int,
-
@PickAmount int
-
-
AS
-
-
SELECT
-
c.CON_ID,
-
c.CON_DESC,
-
p.PROD_ID,
-
p.PROD_NAME,
-
pic.PICKINSTRLINE_ID,
-
pic.PICKINSTRLINE_QTY_NEEDED,
-
t.TOTE_ID,
-
t.TOTE_NR
-
FROM TBLCONTAINERS c
-
INNER JOIN TBLPRODUCT p WITH(NOLOCK) ON p.PROD_ID = c.PROD_ID
-
INNER JOIN TBLPICKINSTRLINES pic WITH(NOLOCK) ON pic.CON_ID = c.CON_ID
-
INNER JOIN TBLTOTES t WITH(NOLOCK) ON t.TOTE_ID = pic.TOTE_ID
-
WHERE c.CON_ID = @BinID
-
AND c.CON_ACTIVE = 1
-
AND p.PROD_ID = @ProductID
-
AND p.PROD_ACTIVE = 1
-
AND t.TOTE_ID = @ToteID
-
AND t.TOTE_ACTIVE = 1
-
AND pic.PICKINSTRLINE_QTY_NEEDED = @PickAmount
-
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#): -
public DataSet populateManualSelectionForEdit(DataSet dataSet, int binID, int productID, int toteID, int pickAmount)
-
{
-
using (SqlConnection connection = InstancesTest.IDataInterface.DefineConnection())
-
{
-
SqlCommand command = new SqlCommand();
-
command.CommandType = CommandType.StoredProcedure;
-
command.CommandText = "usp_PopulateManualSelectionForEdit";
-
command.Connection = connection;
-
-
try
-
{
-
if (connection.State == ConnectionState.Closed)
-
{
-
connection.Open();
-
}
-
-
command.Parameters.Add("@BinID", SqlDbType.Int);
-
command.Parameters["@BinID"].Value = binID;
-
command.Parameters.Add("@ProductID", SqlDbType.Int);
-
command.Parameters["@ProductID"].Value = productID;
-
command.Parameters.Add("@ToteID", SqlDbType.Int);
-
command.Parameters["@ToteID"].Value = toteID;
-
command.Parameters.Add("@PickAmount", SqlDbType.Int);
-
command.Parameters["@PickAmount"].Value = pickAmount;
-
-
command.ExecuteNonQuery();
-
-
SqlDataAdapter da = new SqlDataAdapter(command.CommandText, connection);
-
da.Fill(dataSet);
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show(ex.ToString(), "Error in Stored Procedure");
-
}
-
finally
-
{
-
if (connection.State == ConnectionState.Open)
-
{
-
connection.Close();
-
}
-
}
-
return dataSet;
-
}
-
}
-
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
3 1787
On line 28 you do -
SqlDataAdapter da = new SqlDataAdapter(command.CommandText, connection);
-
So just the CommandText will be executed (without parameters)
You could do it like that: -
SqlDataReader dr = command.ExecuteReader();
-
System.Data.DataSet ds = new System.Data.DataSet();
-
System.Data.DataTable dt = new System.Data.DataTable("table");
-
dt.Load(dr);
-
ds.Tables.Add(dt);
-
Thanks a lot, seems to have worked and what you said makes sense..."The CommandText will be executed (without parameters)"
You could also default your SQL input parameters:
@BinID int DEFAULT -1
Or something like that
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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...
|
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...
| |
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. ...
|
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.
|
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...
|
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....
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |