如何更新最近插入的值 [英] how to update recently inserted value

查看:95
本文介绍了如何更新最近插入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我的sql数据库中有3个表

1.用户信息
UserID int
UserLoginName varchar
密码varchar

2.BankMaster
BankID int
UserID int
BankName varchar
分支名称varchar
AccountNo int
minBalance int

3.存款
DepositeID int
bankID int
金额int
ClosingBalance int



我已经在aspx.cs页面中写了查询


受保护的无效btnModify_Click(对象发送者,EventArgs e)

hi
i have 3 table in my sql database

1.Userinfo
UserID int
UserLoginName varchar
password varchar

2.BankMaster
BankID int
UserID int
BankName varchar
Branchname varchar
AccountNo int
minBalance int

3.Deposite
DepositeID int
bankID int
Amount int
ClosingBalance int



I have written query in aspx.cs page


protected void btnModify_Click(object sender, EventArgs e)

String s = "update BankMaster 
                
           set MinBalance=Deposit.ClosingBalance                  
               
            from BankMaster,Deposit,Userinfo 
               
            where BankMaster.BankID=Deposit.BankID and 
               Userinfo.Loginname='" + Session["uname"] + "'";


我的任务是根据特定用户的登录名从表Deposit中更新BankMaster表minBalance
上面的查询正在更新,但我希望最近插入的值应更新为特定的用户登录名,该如何为此提供帮助


在此先感谢


my task is update BankMaster table minBalance from the table Deposit according to the which particular user login
this above query is updating but i want recently inserted value should update to the particular user login how to do this help me for this


thanks in advance

推荐答案



为此,您需要使用事务或存储过程.

在其中,您可以使用Scope_Identity()来获取当前事务中最新插入的身份.

现在,您具有当前插入的ID,因此您可以执行任何想做的事情.

问候
Ankit
Hi,

For this purpose you need to use transactions or Stored Procedures.

Within that You can use Scope_Identity() to get the latest inserted identity in the current transaction.

Now you have the currently inserted ID so you can do whatever you want to do.

Regards
Ankit


通过使用-
从TableName中选择*,其中ID = @@ Identity

之后,您将获得当前的插入行.
by using,-
select * from TableName where ID=@@Identity

After that you will get the current Inserted Row.


这篇关于如何更新最近插入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆