多表存储修改

S
--联查反填
 go
alter proc pro_getStudentID @stid int 
 as
  select A.*,B.XID from dbo.TStudent as A inner join dbo.TClass as B on A.BID=B.BID  where A.stid = @stid
  --执行联查存储
 exec pro_getStudentID  @stid


 go
create proc pro_uptStudent @stid int ,@BID int , @stName nvarchar(50), @stSex nvarchar(50)
as
update dbo.TStudent set stid=@stid,BID=@BID,stName=@stName,stSex=@stSex

exec pro_uptStudent


---修改
go
create proc p_Update @stid int, @BID int, @stName nvarchar(50), @stSex nvarchar(50),@XID int
as 
begin
 begin tran
  begin try
      update dbo.TStudent set stName=@stName,stSex=@stSex,BID=@BID where stid=@stid
      update dbo.TClass set XID=@XID where BID=(select BID from dbo.TStudent where stid=@stid)    
   commit tran
  end try
   begin catch
    rollback tran
   end catch
end

exec p_Update  @stid , @BID , @stName , @stSex ,@XID

D

 /// <summary>
        /// 单个查找
        /// </summary>
        public NewStudent findStudent(int stid)
        {
            var get = context.Database.SqlQuery<NewStudent>(" exec pro_getStudentID  @stid", new SqlParameter("@stid", stid));
            return get.FirstOrDefault();
        }
        /// <summary>
        /// 修改
        /// </summary>
        public int UptStudent(int stid, int BID, string stName, string stSex, string XID)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
          {
                new SqlParameter("@stid",stid),
                new SqlParameter("@BID",BID),
                new SqlParameter("@stName", stName),
                new SqlParameter("@stSex", stSex),
                new SqlParameter("@XID",XID),
           };
            return context.Database.ExecuteSqlCommand("exec p_Update  @stid , @BID , @stName , @stSex ,@XID", sqlParameters);
        }

W
 /// <summary>
        /// 单个查找
        /// </summary>
        [WebMethod]
        public void findStudent(int stid)
        {
            Context.Response.ContentType = "application/json";
            NewStudent get = stbll.findStudent(stid);
            var json = JsonConvert.SerializeObject(get);
            Context.Response.Write(json);
        }

        /// <summary>
        /// 修改
        /// </summary>
        [WebMethod]
        public void UptStudent(int stid, int BID, string stName, string stSex, string XID)
        {
            Context.Response.ContentType = "application/json";
            int i = stbll.UptStudent(stid, BID, stName, stSex, XID);
            Context.Response.Write(i);
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值