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 my value has to be a dataColumn from my dataset and addWithValue does not take a dataColumn from what I saw. (correct me if I'm wrong)

Thanks!

Recommended Answers

All 6 Replies

What's the value of doCarrier.ColumnName?

Did you want to store the name of the column (doCarrier.ColumnName) or did you mean to use the columns value? What type is doCarrier in your code?

Thanks everyone for your help. It seemed to work by splitting my updates into 2 separate stored procedures. If anyone knows the reason for this, I would appreciate it.

Thank you!

Without knowing what you've changed its hard to know why it might have worked.
If you can post your new seperate stored procedures we can try and explain it for you.

I figured it out. For anypne else out there: it's because I didn't specify which tables in my dataset were getting updated. And when I tried specifying, I only specified 1 table while my stored procedure was updating 2 out of 4 in my dataset. I was not able to just update everything because 2 of my tables were from a different server (not linked).

It worked by creating 2 separate update commands and stored procedures- 1 for each table.

If anyone has a way to still combine this into 1 stored procedure/update command, I would appreciate it. Because although you can update the whole dataset at once, I did not see a way to specify more than 1 table to update.

Thanks all for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.