TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mahmoud Alyan
NA
10
15.3k
How to update a record with primary key using stored procedure.
Feb 19 2011 11:00 AM
Can any one help me to update the primary key using stored procedure as I'm having an error
but when I tried to update the record using a condition it work, (LaptopID is the primary key).
But when I try to update the primary key with the second code it doesn't work as the condition (Where LaptopID=@LaptopID) will be changed, and I don't want to make another stored procedure with another condition when I update the record with the primary key.
the code I used to update the stored procedure is:
ALTER PROCEDURE Update_Data_SP
(
@LaptopID varchar(50),@StudentID varchar(50),@Manufacturer varchar(50),@Model varchar(50),@AcquistionYear varchar(50),@History nvarchar(MAX),
@Comments nvarchar(MAX)
)
AS
Update Laptops_Table set LaptopID=@LaptopID, StudentID=@StudentID, Manufacturer=@Manufacturer,
Model=@Model, AcquistionYear=@AcquistionYear, History=@History, Comments=@Comments
When I used a condition worked:
ALTER PROCEDURE Update_Data_SP
(
@LaptopID varchar(50),@StudentID varchar(50),@Manufacturer varchar(50),@Model varchar(50),@AcquistionYear varchar(50),@History nvarchar(MAX),
@Comments nvarchar(MAX)
)
AS
Update Laptops_Table set LaptopID=@LaptopID, StudentID=@StudentID, Manufacturer=@Manufacturer,
Model=@Model, AcquistionYear=@AcquistionYear, History=@History, Comments=@Comments WHERE LaptopID=@LaptopID
The thing is I want to update even the primary key which will not work because if I changed the the primary key the condition (Where LaptopID=@LaptopID) will not be valid.
Any suggestion or idea if there is any way I can update the record including the primary key in one stored procedure???
Reply
Answers (
3
)
Change Excel Date Format using C#
Updating database with datatable