日期:2014-05-17  浏览次数:20662 次

SQL 使用存储过程问题
调用了以下的存储过程,如果更新错误一条,应该回滚,为什么我每次返回值还取到1.


在线等 跪求答案

alter proc UpdateSMProudctAndSMRelOrgProduct
@PKId uniqueidentifier,@ProductName nvarchar(40),@ContactName nvarchar(40),@ContactEmail nvarchar(40),@ContactTel nvarchar(40),@BAk nvarchar(40)
as 
begin tran
declare @Sumerror int
update SMProduct set Name=@ProductName where PKID=@PKId

update SMRelOrgProduct set ContactName=@ContactName,ContactEmail=@ContactEmail,ContactTel=@ContactTel,Bak1=@BAk where ProductPKID=@PKId
if @@ERROR<>0
begin rollback transaction 
return 0
end 
else
begin commit transaction
return 1
end



方法
  public int UpadateSMproductandOrg(Guid Pkid,SMProduct SMEntity,SMRelOrgProduct SMOrgEntity)
        {
            List<String> SQLStringList = new List<string>();
            StringBuilder strSql = new StringBuilder();
         
            
            SqlParameter[] parameters = {
                   
new SqlParameter("@PKId", SqlDbType.UniqueIdentifier,16),
                    new SqlParameter("@BAk", SqlDbType.NVarChar),
                    new SqlParameter("@ContactName", SqlDbType.NVarChar),
new SqlParameter("@ContactEmail", SqlDbType.NVarChar),
                   new SqlParameter("@ContactTel", SqlDbType.NVarChar),
                   new SqlParameter("@ProductName", SqlDbType.NVarChar)
                 };
            parameters[0].Value = Pkid;
            parameters[1].Value = SMOrgEntity.bak1;
            parameters[2].Value = SMOrgEntity.ContactName;
            parameters[3].Value = SMOrgEntity.ContactEmail;
            parameters[4].Value = SMOrgEntity.ContactTel;
            parameters[5].Value = SMEntity.Name;

            int i;
            DbHelperSQL.RunProcedure("UpdateSMProudctAndSMRelOrgProduct", parameters, out i);
            return i;

        }

<