My .Net code: -
connDO.Open();
-
SqlCommand comm = new SqlCommand("DOrders.dbo.p_Update", connDO);
-
comm.CommandType = CommandType.StoredProcedure;
-
daDirectOrders.UpdateCommand = comm;
-
-
comm.Parameters.Add("@UOrderNumber", SqlDbType.Int, 32, uOrderNumber.ColumnName);
-
comm.Parameters.Add("@ConfirmationCode", SqlDbType.VarChar, 50, confirmationCode.ColumnName);
-
comm.Parameters["@ConfirmationCode"].SourceVersion = DataRowVersion.Original;
-
comm.Parameters.Add("@Carrier", SqlDbType.VarChar, 50, doCarrier.ColumnName);
-
comm.Parameters.Add("@Tracking", SqlDbType.VarChar, 50, doTracking.ColumnName);
-
comm.Parameters.Add("@OrderID", SqlDbType.Int, 32, orderID2.ColumnName);
-
comm.Parameters["@OrderID"].SourceVersion = DataRowVersion.Original;
-
comm.Parameters.Add("@LineItem", SqlDbType.Int, 32, lineItem.ColumnName);
-
comm.Parameters["@LineItem"].SourceVersion = DataRowVersion.Original;
-
-
daDirectOrders.Update(dataSet);
-
connDO.Close();
-
My Stored Procedure: -
@UOrderNumber int,
-
@ConfirmationCode varchar(50),
-
@Carrier varchar(50),
-
@Tracking varchar(50),
-
@OrderID int,
-
@LineItem int
-
-
AS
-
BEGIN
-
-
SET NOCOUNT ON;
-
-
UPDATE Orders
-
SET UOrderNumber = @UOrderNumber
-
WHERE ConfirmationCode = @ConfirmationCode
-
-
UPDATE OrdersDetail
-
SET Carrier = @Carrier, Tracking = @Tracking, LastUpdated = GETDATE()
-
WHERE OrderID = @OrderID and LineItem = @LineItem
-
-
-
END
-
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!
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
The problem is, your parameter doesn't have a value supplied.
If you don't want to use AddWithValue, you can do the follwing: -
comm.Parameters.Add("@Carrier", SqlDbType.VarChar, 50, doCarrier.ColumnName).Value = ...;
-
The Add-method returns the SqlParameter which was added.
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?
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?
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.
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.
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?
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?
is doCarrier.ColumnName an empty string or null?
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).
U Can use following code :
comm.Parameters.Add("@Carrier", SqlDbType.VarChar).Value = doCarrier.ColumnName;
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |