Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
In my project I need to update edited values. I have created an sp for that tha works fine. I got all the edited values on data layer, business layer and presentation layer as well. But the values are not updated in my db table.
Here is my datalayer code:
C#
public object Update(object ObjEditItem)
        {
            try
            {
             BusinessObjects.Common.TransactionDetail objEditTransactionDetail = new BusinessObjects.Common.TransactionDetail();
                string spName = "spUpdateItemHeader";
                Database db = DatabaseFactory.CreateDatabase(ConnectionString);
                DbCommand dbCommand = db.GetStoredProcCommand(spName);
                db.AddInParameter(dbCommand, "@ItemID", DbType.String, ((BusinessObjects.Tables.aItem)ObjEditItem).ItemID);
                db.AddInParameter(dbCommand, "@ItemCode", DbType.String, ((BusinessObjects.Tables.aItem)ObjEditItem).ItemCode);
                db.AddInParameter(dbCommand, "@ItemDescription", DbType.String, ((BusinessObjects.Tables.aItem)ObjEditItem).ItemDescription);

db.AddOutParameter(dbCommand, "@TransactionId", DbType.Int32, 100);
               db.AddOutParameter(dbCommand, "@TransactionNo", DbType.String, 100);
               db.ExecuteScalar(dbCommand);
               if (db.GetParameterValue(dbCommand, "@TransactionId") != DBNull.Value)
               {
                   objEditTransactionDetail.TrnsactionId = Convert.ToInt32(db.GetParameterValue(dbCommand, "TransactionId"));
               }
               if (db.GetParameterValue(dbCommand, "@TransactionNo") != DBNull.Value)
               {
                   objEditTransactionDetail.TrnsactionNo = Convert.ToString(db.GetParameterValue(dbCommand, "TransactionNo"));
               }
               return objEditTransactionDetail;
           }
Posted
Comments
Prasad Avunoori 27-Jun-14 5:19am    
Why don't you put a break point and see what's happening over there?
My Doubt 27-Jun-14 5:21am    
yea I have tried break points.. I got inserted values in C#, thats fine. But sql table is not updated.

You are doing an update, hence it should be ExecuteNonQuery. ExecuteScalar is a select only statement that return a single record that has a single column.
 
Share this answer
 
Start by looking at your stored procedure: since you just pass it values and let it get on with the work, you need to look and see exactly what it is doing with it, since the problem is likely to be there.

It'd probably be a good idea to see if it's throwing any exceptions - you don't show your catch block so we have no idea if you are examining exceptions or just discarding them. Any error message is very likely to be relevant.
 
Share this answer
 
Comments
My Doubt 27-Jun-14 5:32am    
It's my SP

CREATE PROCEDURE spUpdateItemHeader (
@ItemID INT
,@ItemCode VARCHAR(50)
,@ItemDescription VARCHAR(250)
,@TransactionId INT OUTPUT
,@TransactionNo NVARCHAR(50) OUTPUT
)
AS
BEGIN
SELECT @ItemCode = ItemCode
,@ItemDescription = ItemDescription
FROM Items
WHERE ItemID = @ItemID
AND @ItemDescription = ItemDescription

BEGIN
UPDATE aItem
SET ItemDescription = @ItemDescription
WHERE ItemID = @ItemID
END

--OUT
SELECT @TransactionId = @ItemID
--SELECT @TransactionNo = ItemDescription
FROM Items
WHERE ItemID = @ItemID
END
My Doubt 28-Jun-14 2:36am    
Dear OriginalGriff,
Its my SP problem, I have corrected it and now it works fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900