Art wrote:
> Pat Shaw wrote:
>
>> Yes, and if the inserts are to two or more tables
use TRANSACTIONS to
>> ensure that all or none are inserted.
> Below is a simplified version of what I came up with. It
works. In other
> words, if it all transacts, it places the info in the
database if not,
> then it should raise an error.
>
> However, I don't know how to pull the RAISEDERROR bit
out into the page.
> Do I somehow use RAISEERROR as a variable?
>
> On the page that writes to the database, I use a
recordset and select
> "Stored Procedure" instead of "command" and stored
procedure (because of
> the bug in Dreamweaver)
>
> With that in mind, how do I pull the error out so that I
can send the
> user to an alternate page that indicates that there was
an error and to
> try again?
>
> Man, there really needs to be a book about this stuff.
Know of one? Want
> to write one?
>
> Anyways, Below is my stored procedure; notice at the
bottom where it
> triggers the error.
>
>
> CREATE Procedure xxx_Insert
> @varFName varchar (50),
> @varLName varchar (50),
> @varPassWord varchar (20),
> @varEmail varchar (50),
> @varShipName varchar (100),
> @varShipSchool varchar (100)
>
> As
>
> BEGIN TRANSACTION
>
> IF NOT EXISTS (
> SELECT EMail
> FROM Customer
> WHERE EMail = @varEmail
> )
> BEGIN
> INSERT INTO Customer (FName, LName, Email, Password)
> VALUES (@varFName, @varLName, @varEmail, @varPassword)
> END
> BEGIN
> INSERT INTO ShipAdd (ShipName, ShipSchool)
> VALUES (@varShipName, @varShipSchool)
> END
>
> IF @@ERROR <> 0
> BEGIN
> --ROLLBACK THE TRANSACTION
> ROLLBACK TRANSACTION
> --RAISE AN ERROR AND RETURN
> RAISERROR ('Could not insert user', 16, 1)
> RETURN
> END
> COMMIT TRANSACTION
> GO
You need to define an output parameter, and then pull that
from your page.
Steve