Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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)

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

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
Posted
Updated 12-Apr-11 23:24pm
v2
Comments
Pong D. Panda 13-Apr-11 5:44am    
ARRRGH! I cant understand what do you want to accomplish here. Can you further elaborate? You mean the script is working but it updates records not only for the user that is currently logged in?
Akshatha.A 13-Apr-11 5:49am    
yes its working but agai when user deposite it update the previous value rather than the currently inserted value
Pong D. Panda 13-Apr-11 6:01am    
can you provide a sample data?

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
 
Share this answer
 
by using,-
select * from TableName where ID=@@Identity

After that you will get the current Inserted Row.
 
Share this answer
 
Comments
Akshatha.A 13-Apr-11 6:17am    
when i use @@identity its inserting twice and increasing the id by 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900