Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables Tenant and lease both have a common field tenant-id
Tenant(tnant-id,fname,lname,age) and lease(lase-id,deposit,entry-date,departure-date,tenant-id)

i have an asp.net sytem where you have to use a last name that already exists to update.meaning you can fill all the other fields with diff values(values you want to update) but the last name has to be of the tenant you want to update their details.

What I have tried:

update Tenants set fname=@fname....
where fname=@fname
update lease set deposit=@deposit
where tenant-id=@tenant-id

it is not working
Posted
Updated 11-Jun-18 22:07pm

1 solution

Well ... look at what you are doing. You are changing the Tenant name to the value that you are starting with! Which means that the first update - by definition - never makes any changes, and if it did would quite likely mess your DB up, as last names aren't even close to unique. And teh hyphens in your column names don't help at all either...
Probably what you meant to do was this:
SQL
UPDATE Tenants SET fname=@fname WHERE [tnant-id] = @tenantId
UPDATE lease SET deposit=@deposit WHERE [tenant-id]=@tenantId

But I'd suggest that you change the column names:
Tenant:
ID, 
fName
lName
Age
Lease
ID
deposit
entryDate
departureDate
tenantID
It's more consistent and easier to work with.
 
Share this answer
 
Comments
Member 11239384 12-Jun-18 4:15am    
yes but how will the system know which record to update because cant feed it with tenant-id it is autogenerated.And i am not using a grid view where i can highlight record to update
OriginalGriff 12-Jun-18 4:24am    
You can't UPDATE a record unless it already exists - which means it has an ID already.
If you want a new ID, then that means you have a new record, and you don't use UPDATE for that, you use INSERT.
Member 11239384 12-Jun-18 4:29am    
now i have tried it like this and it is not updating .cause it doesn't know which id to update.should i create a textbox to enter the id ?
OriginalGriff 12-Jun-18 4:50am    
How are you going to use a TextBox in a Stored Procedure? :laugh:
The SQL Server doesn't have any direct access to your user...

I think you need to take a step back for a moment, and think about exactly what you are trying to achieve, instead of the mechanics of how to implement it - you seem a little confused as to what an update is all about.

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