Reputation: 2200
I use a stored procedure for inserting, updating and deleting records, and I use LINQ for executing or calling the procedures. After clicking on submit button, the update procedure has been executed but there is no change in the table! If I pass a value like "Jack" instead of fname_txt.text, it works and is updated. I don't know what's the different between a textbox object and a value in a quotation mark?! Here is the code:
protected void submit_Click(object sender, EventArgs e)
{
try
{
ZobLinqDataContext db = new ZobLinqDataContext();
string pasword = CryptorEngine.Encrypt(pass_txt.Text, true);
long uid = Convert.ToInt64(Request["uid"]);
db.pUpZDBUser(uid,
uname_txt.Text,
pasword,
fname_txt.Text.Trim(),
lname_txt.Text.Trim(),
modir.Checked,
voting.Checked,
Convert.ToInt32(Zarib_txt.Text),
false
);
db.SubmitChanges();
Response.Write(uname_txt);
}
finally
{
Session["sub"] = "1";
}
}
this is the update proc:
USE [ZOBDB]
GO
/****** Object: StoredProcedure [dbo].[pUpZDBUser] Script Date: 04/11/2012 15:17:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pUpZDBUser]
@UID bigint,
@Uname nvarchar(100),
@Pass nvarchar(100),
@fname nvarchar(50),
@lname nvarchar(50),
@KU bit,
@KV bit,
@ZribV int,
@del bit
As
BEGIN TRANSACTION UpUser
Set NOCOUNT ON
UPDATE Users SET
Uname=@Uname,
Pass=@Pass,
fname=@fname,
lname=@lname,
KU=@KU,
KV=@KV,
ZribV=@ZribV,
del=@del
where (UID=@UID)
--RollBack if Err
IF @@ERROR != 0 and @@ROWCOUNT != 1
BEGIN
declare @msg nvarchar(30)
set @msg = ' error '+@Uname
ROLLBACK
RAISERROR(@msg,16,1)
RETURN
END
COMMIT TRANSACTION UpUser
RETURN
Upvotes: 0
Views: 98
Reputation: 107267
I think you'll have more luck if you change the SPROC to
--RollBack if Err
IF @@ERROR != 0 **OR** @@ROWCOUNT != 1
This way you should get the error being raised and you can see what the issue is. Possibly the UID doesn't exist?
Upvotes: 1
Reputation: 21098
Best guess is that your proc is throwing an exception that you're not catching, perhaps because there's a length constraint on the column, and that your fname_txt.Text.Trim()
value is zero length, and "Jack" of course is not.
Add a catch block to your code to prover there is nothing untoward happening in your proc. Also more detail in your question would be helpful.
Upvotes: 0