• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

go from insert view to edit view in a formview after an insert is made.

I want to have the user enter their data into the "insert" portion of a formview, click the insert button and have the system save the info, then return the user to the edit mode.

You'd think this would be pretty standard....  

I figured there must be a better way to do this than writing a procedure to pull the identity.  Isn't there some fancy dotnet option?  Somewhere I saw someone using a select @@IDENTITY statement after the sql statement used on the insert option of the sql datasource.

  • 3
1 Solution
I would say what you want to do is create a stored procedure that has an output parameter to hold the inserted id on completion of the insert. When creating this procedure, you should also use "Scope_Identity()" instead of @@IDENTITY when using SQL Server. Once you have the sql stored procedure setup to fill the output variable, in your form view's ItemInserted event, retrieve this parameters value from your sql data source for the id and then use the formview's changemode() method to put the formview in edit mode.
DanielcmorrisAuthor Commented:
That's pretty much what I've been doing.  I just thought, since microsoft has gone soooo far out of it's way to make all the datacode for their data-objects into the "HTML" section of the page rather than the coded section, Perhaps they had built in a feature that would automatically do this for me.

To be honest, I am really not all that big a fan of this .net stuff.  I really liked old fashioned asp.  Other than the debugging features of .net, it's really a bit of a pain.  I had assumed that "FormView", being the primary data form, would have a billion features built in, but I'm discovering that it is a LOT easier to write the code with a bunch of text boxes and just assign values from code.  It would certainly be a lot easier than writing the exact same form for INSERT as EDIT, where you've got to change both if your client wants a change.

I think I'm just going to ditch FormView altogether unless there is some feature that I'm not missing.
DanielcmorrisAuthor Commented:
 "not missing" --- um, I meant, "not getting"
Daniel, I wish to do what you are talking about here, but I want to use a formview.  I understand how to do the stored procedure.  HOWEVER, I do not understand how to retrieve the parameter in the ItemInserted event as TSmooth states above.  Would you mind posting the code to retrieve the parameter??

Thanks, Mark
DanielcmorrisAuthor Commented:
Mark,  I'll tell you what I did:

I inserted the record.  Then:
select max(contactid) from contacts


I'm used to using SQL Server and I just got tired of trying to get MS Access to work with @@IDENTITY and scope... etc...  The system is only used by about 10 people and I wasn't going to spend any more time on it.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now