Get SqlDataSourceStatusEventArgs for FormView ItemInserted

Joined
Mar 23, 2008
Messages
1
Reaction score
0
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...

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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top