473,406 Members | 2,281 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,406 software developers and data experts.

Why isn't my stored procedure recognizing my parameter from my code?

14
My .Net code:
Expand|Select|Wrap|Line Numbers
  1.  connDO.Open();
  2.                     SqlCommand comm = new SqlCommand("DOrders.dbo.p_Update", connDO);
  3.                     comm.CommandType = CommandType.StoredProcedure;
  4.                     daDirectOrders.UpdateCommand = comm;
  5.  
  6.     comm.Parameters.Add("@UOrderNumber", SqlDbType.Int, 32, uOrderNumber.ColumnName);
  7.                     comm.Parameters.Add("@ConfirmationCode", SqlDbType.VarChar, 50, confirmationCode.ColumnName);
  8.                     comm.Parameters["@ConfirmationCode"].SourceVersion = DataRowVersion.Original;
  9.                     comm.Parameters.Add("@Carrier", SqlDbType.VarChar, 50, doCarrier.ColumnName);
  10.                     comm.Parameters.Add("@Tracking", SqlDbType.VarChar, 50, doTracking.ColumnName);
  11.                     comm.Parameters.Add("@OrderID", SqlDbType.Int, 32, orderID2.ColumnName);
  12.                     comm.Parameters["@OrderID"].SourceVersion = DataRowVersion.Original;
  13.                     comm.Parameters.Add("@LineItem", SqlDbType.Int, 32, lineItem.ColumnName);
  14.                     comm.Parameters["@LineItem"].SourceVersion = DataRowVersion.Original;
  15.  
  16.                     daDirectOrders.Update(dataSet);
  17.                     connDO.Close();
  18.  
My Stored Procedure:
Expand|Select|Wrap|Line Numbers
  1.     @UOrderNumber int,
  2.     @ConfirmationCode varchar(50),
  3.     @Carrier varchar(50),
  4.     @Tracking varchar(50),
  5.     @OrderID int,
  6.     @LineItem int
  7.  
  8. AS
  9. BEGIN
  10.  
  11.     SET NOCOUNT ON;
  12.  
  13.     UPDATE Orders 
  14.         SET UOrderNumber = @UOrderNumber
  15.         WHERE ConfirmationCode = @ConfirmationCode
  16.  
  17.     UPDATE OrdersDetail
  18.         SET Carrier = @Carrier, Tracking = @Tracking, LastUpdated = GETDATE()
  19.         WHERE OrderID = @OrderID and LineItem = @LineItem
  20.  
  21.  
  22. END
  23.  
When I run, I get the following error:

Procedure or function 'p_update' expects parameter '@Carrier' which was not supplied

Why isn't is recognizing my parameter? Also, it does not give a problem with @UOrderNumber and @ConfirmationCode. And when I do Parameters.AddWithValue and pass a string value, it does work. The problem is, that addWithValue does not take a dataColumn from what I saw. (correct me if I'm wrong)

Thanks!
Sep 8 '10 #1

✓ answered by Christian Binder

Which DataTables are inside your DataSet? Maybe it doesn't know from which DataTable to take the columns.
I've had a look there.

Are you able to send me some more code (including sql-tables), so I could try a little on my own?

10 1861
Christian Binder
218 Expert 100+
The problem is, your parameter doesn't have a value supplied.
If you don't want to use AddWithValue, you can do the follwing:

Expand|Select|Wrap|Line Numbers
  1. comm.Parameters.Add("@Carrier", SqlDbType.VarChar, 50, doCarrier.ColumnName).Value = ...;
  2.  
The Add-method returns the SqlParameter which was added.
Sep 8 '10 #2
LELE7
14
But my value is the data from the datacolumn in my dataset. When I do ".Value=dataColumn" I still get the same error.
By the way, this same code worked when it was not a stored procedure, but SQL in my code. How does that make sense?
Sep 8 '10 #3
Christian Binder
218 Expert 100+
Oh, I see. I have never used SqlParameters with source-columns.
What if you set the SourceVersion-property for @Carrier like you did on the other parameter? (comm.Parameters["@Carrier"].SourceVersion = DataRowVersion.Original;)

When you debug, does dataSet have a column named like the value of doCarrier.ColumnName?
Sep 8 '10 #4
LELE7
14
The sourceVersion property is used for the column that is acting as my primary key. Original, I believe, means that it was not changed. I tried DataRowVersion.current which did not help. I tried specifying parameter direction and source column again, but nothing seemed to help.

The column exists in the dataSet with that name, so I am going out of my mind.

Isn't this a common thing- to update a database from a dataset? There were so few examples online, but my code does seem to follow everything exactly. Also, like I mentioned, the first part of my stored procedure works, so that makes me even more confused.
Sep 8 '10 #5
Christian Binder
218 Expert 100+
Maybe it's a problem with datatypes/length? What's the datatype of doCarrier.ColumnName-column in dataSet?

I've never used that way for updating a database...

If you add the param with AddWithValue (and a test-string) for @Carrier, does it work? I think of this because @Tracking-param is done the same way. So we could figure out, if the problem is definitly the @Carrier-param.
Sep 8 '10 #6
LELE7
14
I checked the datatypes a lot of times and everything matches the database.

A test string does work. The problem comes up just for @Carrier because it's first. If I put a test string, then @Tracking pops up... etc.

Is there another way to update a database that would work in this situation?
Sep 8 '10 #7
Christian Binder
218 Expert 100+
Which DataTables are inside your DataSet? Maybe it doesn't know from which DataTable to take the columns.
I've had a look there.

Are you able to send me some more code (including sql-tables), so I could try a little on my own?
Sep 9 '10 #8
Plater
7,872 Expert 4TB
is doCarrier.ColumnName an empty string or null?
Sep 9 '10 #9
LELE7
14
Thanks Christian! That was it. I actually figured it out becaue it worked when I split into 2 stored procedures- 1 for each table.

Just curious, is there a way to choose more than 1 table in a dataset to update with 1 update command? I know there's a way to specify 1 table, or the whole datset (which is 4 tables in this case).
Sep 12 '10 #10
U Can use following code :

comm.Parameters.Add("@Carrier", SqlDbType.VarChar).Value = doCarrier.ColumnName;
Sep 13 '10 #11

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

Similar topics

4
by: stjulian | last post by:
I have a stored procedure that is supposed to 1. Increment a counter in Table A via a transaction 2. Use this value as the primary key to add in an address to customers Table B (Referenced as a...
5
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
1
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME,...
4
by: William F. Robertson, Jr. | last post by:
One of my developers came to me with this question and I don't have an answer for them. The only suggestion I had for them was to change the return to a output parameter and put a try catch around...
1
by: Justin | last post by:
I am trying to query two tables with a stored procedure but I get the following error: "Procedure Details has no parameters and arguments were supplied." Here is my stored procedure as created...
2
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
2
by: vinodkus | last post by:
I am Beginner in ASP Problem:I have a table named emp which fields are(id int(4), name varchar(50), rollNo int(4)) I have to just pass the name of the emp and it will just say that record is...
4
by: stjulian | last post by:
(IIS 6.0, SQL Server 2000) I have a block of code that populates a recordset from a stored procedure. The problem is, the recordset seems to be forward only (which would be OK), but can't jump...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...

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.