zoukankan      html  css  js  c++  java
  • 一个表插入操作成功后执行另一个表的插入操作(存储过程、事务)

    存储过程

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    ALTER proc [dbo].[memberproductInsert]
    @Name varchar(50),
    @TypeID varchar(50),
    @KeyWord nvarchar(40),
    @Picture nvarchar(100),
    @Detail text,
    @AddDate datetime,
    @Price float,
    @UserID int,
    @Verify int,
    @Sort int,
    @Ask varchar(100),
    @IsTop bit,
    @LastDate datetime,
    @Money float

    AS
    Begin
       begin transaction AddproductInfo
        declare @ID int
        insert into w_products ([Name],TypeID,KeyWord,Picture,Detail,AddDate,Price) values(@Name,@TypeID,@KeyWord,@Picture,@Detail,@AddDate,@Price)
        set @ID = scope_identity()
        insert into w_usersproducts (UserID,ProductID,Verify,Sort,AddDate,Ask,IsTop,LastDate,[Money]) values(@UserID,@ID,@Verify,@Sort,@AddDate,@Ask,@IsTop,@LastDate,@Money)
        if @@Error<>0
        begin
         Rollback transaction AddproductInfo
        end
       commit transaction AddproductInfo
    End

    调用存储过程方法

    public int memeberProInsert(memeberProduct pro)
            {
                SqlParameter[] commentParameter = new SqlParameter[]
                {
                    new SqlParameter("@name",pro.Name),
                    new SqlParameter("@TypeID",pro.TypeId),
                    new SqlParameter("@KeyWord",pro.KeyWord),
                    new SqlParameter("@Picture",pro.Picture),
                    new SqlParameter("@Detail",pro.Detail),
                    new SqlParameter("@AddDate",pro.AddDate),
                    new SqlParameter("@Price",pro.Price),
                    new SqlParameter("@UserID",pro.UserId),
                    new SqlParameter("@Verify",pro.Verify),
                    new SqlParameter("@Sort",pro.Sort),
                    new SqlParameter("@Ask",pro.Ask),
                    new SqlParameter("@IsTop",pro.IsTop),
                    new SqlParameter("@LastDate",pro.LastDate),
                    new SqlParameter("@Money",pro.Money)
                };
                return SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "memberproductInsert", commentParameter);
            }

  • 相关阅读:
    [置顶] 签名时出错: 未在路径 C:Program Files (x86)Microsoft SDKsWindowsv7.0Ainsigntool.exe 找到 SignTool.ex
    频繁绑定DataGridView的DataSource却不正常显示
    生产者消费者模型 android
    Android Studio安装插件的三种方式
    Android Studio插件安装
    数据调试~~TCP转串口、串口转TCP调试
    Socket看法
    android颜色color.xml设置
    博客导航——一站式搜索
    dx.jar文件问题,有没有同学知道怎么解决呀,这一步没法解决,后面就没办法跟着做了
  • 原文地址:https://www.cnblogs.com/yhdkzy/p/2014873.html
Copyright © 2011-2022 走看看