Hi I've created a form that updates a database. My problem is, while online, two people can concurrently attempt to update a record in the database but thanx to the stored procedure's T-SQL, only the first person to post his record will be able to update the
database. I would like to redirect users who have successfully updated the database to Advertisethanx.aspx & those who were unsuccessful to Advertisesorry.aspx. How should I modify the eventhandler code for the update button below? private void btnBuy_Click(object
sender, System.EventArgs e) { cmdGoldupdate.Parameters["@timer"].Value = ddlTimer.SelectedItem.Text; cmdGoldupdate.Parameters["@org"].Value = txbOrg.Text; cmdGoldupdate.Parameters["@url"].Value = txbUrl.Text; cmdGoldupdate.Parameters["@email"].Value = txbEmail.Text;
cmdGoldupdate.Parameters["@message"].Value = txbMessage.Text; conn_IDSLadvertising.Open(); cmdGoldupdate.ExecuteNonQuery(); conn_IDSLadvertising.Close(); if (Response.BufferOutput == true) { Response.Redirect("Advertisethanx.aspx"); } else { Response.Redirect("Advertisesorry.aspx");
} }
Hi I tried that and it didn't work. I read somewhere that return values and parameters that return the number of rows afected in a transaction, only work for select stored procedures in commands & not for update, delete or insert. So do you have any other ideas?
Hi Nstephen, ::I read somewhere that return values and parameters that return the number of rows afected in a transaction, only work for select stored procedures in commands & not for update, delete or insert.
Nonsense! I can return any integer value I want in a return val at anytime and then process whatever that is in the aspx page. Consider the following sproc... If there is an error, it rollsback the update and returns 1. From that return val I know what
happened and can handle that circumstance in the aspx page. If it returns 0, I know the update happened. All you have to do is tweek your SProc accordingly and then simply handle the return val in aspx page. Its really quite simple.
CREATE PROC sp_NewProc
@SomeVar int
As
DECLARE @ErrorNum
BEGIN TRAN
UPDATE myTable
SET myCloumn = 'Something'
WHERE aNotherColumn = @SomeVar
SELECT @ErrorNum = @@Error
IF @Num != 0
BEGIN
ROLLBACK TRAN
RETURN(1)
END
ELSE
BEGIN
COMMIT TRAN
RETURN(0)
END
:-D JB
John Belthoff
Dodge, Duck, Dip, Dive & Dodge
If a man can dodge a wrench, he can dodge a ball!
Nstephen
Member
20 Points
4 Posts
Somebody Help
Aug 02, 2003 12:06 PM|LINK
russnem
Contributor
7001 Points
1389 Posts
ASPInsiders
MVP
Re: Somebody Help
Aug 02, 2003 07:00 PM|LINK
Nstephen
Member
20 Points
4 Posts
Re: Somebody Help
Aug 04, 2003 03:14 PM|LINK
russnem
Contributor
7001 Points
1389 Posts
ASPInsiders
MVP
Re: Somebody Help
Aug 04, 2003 10:20 PM|LINK
JBelthoff
Member
553 Points
135 Posts
Re: Somebody Help
Aug 04, 2003 11:04 PM|LINK
Dodge, Duck, Dip, Dive & Dodge
If a man can dodge a wrench, he can dodge a ball!