I have writtent the following code to do a simple update operation, UI is a DataGrid according to my test new data passes to the Update() also the orignal data was preserved and the problem in in the update stored procedure.. could any one see whats the problem is?
I have the folllwong in update() with the code:
Java
publicintUpdate(int iEmpIndex, string strPassword, string
strFirstName,
string strLastName, int iDesigIndex, int
iUsedAnnualLeaves,
int iUsedSickLeaves, DateTime enteredate, DateTime
updatedDate)
{
try
{
//updating the DB: VALUES PASSED CORRECTLY BUT DOESNT PERFORM THE
TASK
return empAdapter.Update(strPassword, strFirstName, strLastName,
iDesigIndex,
iUsedAnnualLeaves, iUsedSickLeaves, enteredate, updatedDate,
this.OldEmpIndex,
this.OldPassword, this.OldFirstName, this.OldLastName,
this.OldDesigIndex,
this.OldUsedAnnualLeaves, this.OldUsedSickLeaves, this.OldEnteredDate,
this.OldUpdatedDate);
}
catch
{
throw;
}
}
thsi update satement maps to the stored procedure that has the followin SQL
query:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER
PROCEDURE [dbo].[ProcUpdateEmployee]
(
@Password
nvarchar(50),
@FirstName nvarchar(50),
@LastName
nvarchar(50),
@DesigIndexint,
@UsedAnnualLeavesint,
@UsedSickLeavesint,
@EntryDate
datetime,
@UpdatedDate datetime,
@Original_EmpIndexint,
@Original_Password nvarchar(50),
@Original_FirstName
nvarchar(50),
@Original_LastName
nvarchar(50),
@Original_DesigIndexint,
@Original_UsedAnnualLeavesint,
@Original_UsedSickLeavesint,
@Original_EntryDate datetime,
@Original_UpdatedDate
datetime,
@EmpIndexint
)
AS
SET NOCOUNT OFF;
UPDATE
[tblEmployees]
SET
[Password] = @Password,
[FirstName] = @FirstName,
[LastName] = @LastName,
[DesigIndex] = @DesigIndex,
[UsedAnnualLeaves] = @UsedAnnualLeaves,
[UsedSickLeaves] =
@UsedSickLeaves,
[EntryDate] = @EntryDate,
[UpdatedDate] = @UpdatedDate
WHERE (([EmpIndex] = @Original_EmpIndex)
AND
([Password] =
@Original_Password)
AND
([FirstName] = @Original_FirstName)
AND
([LastName] = @Original_LastName)
AND
([DesigIndex] =
@Original_DesigIndex)
AND
([UsedAnnualLeaves] =
@Original_UsedAnnualLeaves)
AND
([UsedSickLeaves] =
@Original_UsedSickLeaves)
AND
([EntryDate] = @Original_EntryDate)
AND
([UpdatedDate] = @Original_UpdatedDate));
SELECT
EmpIndex, Password, FirstName, LastName, DesigIndex, UsedAnnualLeaves,
UsedSickLeaves, EntryDate, UpdatedDate FROM tblEmployeesWHERE(EmpIndex =
@EmpIndex)
But those two dont work... eg.: if i chaneg the value in FirstName from John to Jon, update doesnt happen? why this happense?
TY
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 12, 2009, 6:24 AM EST
0
Friend,
Can you Provide me the Database ???? or Project Files (zip)
petre ricardo155 reputationPosted Nov 14, 2009, 1:04 AM EST
0
Hi Friend,
Thanks for your efforts on solving the problem : ) i really appriciate it..... : )
In mys post i have mentioned two issues with my code it was written to update and throw errors on concurrecy violations. However you were able solve the update it (works perfectly fine) but the Exception DBConccurectException is not thrown by the program in a concurrecy violation.
So the second issue was not solved : ( I've debuged it (i havent made any alterations to your code) i figured it doesnt perform any updated on concurrecy violations but it doesnt throw the exception... Any ideas on why it doesnt throw this exception in concurrency violations?
Thanks
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 12, 2009, 6:24 AM EST
Can you Provide me the Database ???? or Project Files (zip)
because cant figure out by just seeing code :)
just upload the zip at http://mediafire.com
and mail me the download link
at
[email protected]
Thank you :)
petre ricardo155 reputationPosted Nov 12, 2009, 6:58 AM EST
TY
Petre
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 13, 2009, 9:02 PM EST
Congrats !!
+[Problem Solved]
the problem was you were comparing the same EmpIndex Two Times well Primary Key of table is EmpIndex so no need to Compare it two times Like below
Where EmpIndex = @OldEmpIndex,
and Again
EmpIndex = @EmpIndex
and I have also Modified Braces of the Stored procedure in Conditions
this was causing problem I have attached Corrected Database Files and Your Solution files you provided
I have Changed The Connection String in app.Config for connecting to my SQL Server.
so just change it according to your SQL Server Configuration again :)
Now Application Updates Perfectly :)
Here is Your Solution Files
Download Project Files
and Friend,
Dont forget to mark "Do you like this answer" check box :)
petre ricardo155 reputationPosted Nov 14, 2009, 1:04 AM EST
Thanks for your efforts on solving the problem : ) i really appriciate it..... : )
In mys post i have mentioned two issues with my code it was written to update and throw errors on concurrecy violations. However you were able solve the update it (works perfectly fine) but the Exception DBConccurectException is not thrown by the program in a concurrecy violation.
So the second issue was not solved : (
I've debuged it (i havent made any alterations to your code) i figured it doesnt perform any updated on concurrecy violations but it doesnt throw the exception...
Any ideas on why it doesnt throw this exception in concurrency violations?
Thanks