Microsoft
Software
Hardware
Network
Question : Find the ID of inserted record from formview
Hey, I'm trying to set a hidden textbox to the value of the ID from a newly inserted record through a formview.
This is what I'm trying to accomplish:
User fills in formsview to insert new customer
-onclick of insert the ID of this new record is set to a hidden text box
--javascript function gets the ID and passes it back to the parent window.
Got everything working, just cant get the ID.
I've found some stuff on this but it all seems to be in c# and i'm using vb. read something about GET SCOPE(), didn't quite understand how I could apply it to this though.
Thanks in advance!
Answer : Find the ID of inserted record from formview
This is how i explained it above, except not in a stored procedure. The 'insertcommand' is making two seperate SQL Statements: first inserting (INSERT INTO) then the second is separated by the ';' and Selecting the same record using '@@Identity' as a new variable '@DepartmentID'.
The '@DepartmentID' needs to be defined as a new 'insertparameter' and since we are receiving a value from this and not sending into it's direction is 'Output'. Now that this @DepartmentID is output to our page we can grab that variable in our code behind using a new method and write it out to a label.
I believe the code translation to VB.Net is:
Protected Sub sdsDepartment_Inserted(ByV
al sender As Object, ByVal e As SqlDataSourceStatusEventAr
gs)
If (e.Exception Is Nothing) Then
lblMessage.Text = String.Format("Department '{0}' successfully added.", e.Command.Parameters("@Dep
artmentID"
).Value)
Else
lblMessage.Text = "Unable to add department."
e.ExceptionHandled = true
End If
End Sub
==========
If you post both your full .aspx and .vb code I can manipulate it for you.
Random Solutions
how to open, review, and edit a .exe file?
windows server 2008 unattended install
TPMAuth.exe error at startup
Macro running very slow
AutoDial from Access without Getting the AutoDial Window
You do not have exclusive access to the database at this time. If you proceed to make changes, you may not be able to save them later.
Attach multiple files to an Outlook message at one time
Formatted Crystal Report
Does csv file support arabic characters ?
Use of Cards.dll in VB.NET