Hi
The following is for a simple table, called Person, with three fields, ID, Name and EmailAddress. I'm using an insert procedure to check if a record exists, then either inserting the record or returning -1, to notify that the insert didn't take place. Here's a example procedure...
It works fine, and when you check for Result in the DataSource Inserted event, it's all good and you can send an error message to the screen. The problem is that when you do this the state is lost and the previous values in the form fields are lost. This is not such a big deal, but it would be if there were, say, 10 fields to fill out.
If you use the FormView ItemInserted event, it will maintian state, but you can't get to the Result returned from the procedure.
I am not sure if this is possible but it would be good to access the SqlDataSourceStatusEventArgs to ge thte returned Result, and maintain state on the submitted fields. Perhaps there's another approach too.
Anyone got any ideas?
Thanks
The following is for a simple table, called Person, with three fields, ID, Name and EmailAddress. I'm using an insert procedure to check if a record exists, then either inserting the record or returning -1, to notify that the insert didn't take place. Here's a example procedure...
Code:
ALTER PROCEDURE [usp_Person_Insert]
(
@ID int = NULL output,
@Name varchar(50),
@EmailAddress varchar(50)
)
AS
DECLARE @Result int
BEGIN TRANSACTION
IF EXISTS
(
SELECT
NULL
FROM [Person] WITH (UPDLOCK)
WHERE [EmailAddress] = @EmailAddress
)
BEGIN
SELECT @Result = -1
END
ELSE
BEGIN
INSERT
INTO [Person]
(
[Name],
[EmailAddress]
)
VALUES
(
@Name,
@EmailAddress
)
SELECT @ID = SCOPE_IDENTITY()
END
IF @Result <> 0
BEGIN
ROLLBACK
END
ELSE
BEGIN
COMMIT
END
If you use the FormView ItemInserted event, it will maintian state, but you can't get to the Result returned from the procedure.
I am not sure if this is possible but it would be good to access the SqlDataSourceStatusEventArgs to ge thte returned Result, and maintain state on the submitted fields. Perhaps there's another approach too.
Anyone got any ideas?
Thanks