zoukankan      html  css  js  c++  java
  • [SQL]向3个表插入数据的存储过程 和 C# 代码

     public int UpdateQty(string strPartID, int iQty, int iUpdateQty, string strBarCode, string strCreaterId)
            {
                int iRet;
                SqlConnection conn = DBConnection.GetConn_SPAIS();
                SqlCommand cmd = new SqlCommand("CSP0203_UpdateQty", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@vcPartID", strPartID);
                cmd.Parameters.AddWithValue("@Qty", iQty);
                cmd.Parameters.AddWithValue("@updateQty", iUpdateQty);
                cmd.Parameters.AddWithValue("@vcBarCode", strBarCode);
                cmd.Parameters.AddWithValue("@vcCreaterId", strCreaterId);
                cmd.Parameters.Add("return", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
    
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    iRet = (int)cmd.Parameters["return"].Value;
                    return iRet;
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                finally
                {
                    conn.Close();
                    
                }
                
            }
    use SPAISdb
    
    go
     alter proc CSP0203_UpdateQty
        
        @vcPartID varchar(50)
       ,@Qty int
       ,@updateQty int
       ,@vcBarCode varchar(50)
       ,@vcCreaterId varchar(50)
       --,@Return int output
    
       
       
     as
     begin  transaction 
        update tStock
            set iStockQty=iStockQty-@Qty+@updateQty 
            where vcPartID=@vcPartID
            
        update tScan
            set decQuantity=decQuantity-@Qty+@updateQty ,decStockNum=decStockNum-@Qty+@updateQty 
            where vcBarCode=@vcBarCode
            
        insert into tUpdateQtyRecord(vcBarCode,vcPartID,iUpdateQty,vcCreaterId)values(@vcBarCode,@vcPartID,@updateQty,@vcCreaterId)
        
     if @@error<>0 
     begin
        rollback transaction
        --set @Return=1
        return -1
     end
     else
     begin
        commit transaction
     end
  • 相关阅读:
    将博客搬至CSDN
    U盘启动盘 安装双系统 详细教程
    vmware安装linux6.3
    hadoop学习之路
    linux重定向总结:如何将shell命令的输出信息自动输出到文件中保存
    AVRO讲解
    MapReduce 工作原理
    lucene索引存储原理
    ES数据库系统
    分流器设备与交换机设备的区别
  • 原文地址:https://www.cnblogs.com/beeone/p/4117490.html
Copyright © 2011-2022 走看看