hfshultz
Posts: 17
|
Posted: 01/15/2004, 8:46 AM |
|
I have a form with the Primary key as an autonumber using ASP 3.0 code on a SQL Server backend. When the new record is created, I want the return page to be the non-editable (all labels) version of the page I have created by having it pass the new primary key from the first page to the non-editable second page confirming the entry. IE, I create a record that gets a number of 10 and then opens the second page where Primary key=10.
I've seen code snippets that add one to the max of the primary key records but this isn't going to work for me since there will be up to 10 people entering information at a time.
Any ideas?
Thanks for your help!
~Frank
|
|
|
Robert Rodgers
|
Posted: 01/15/2004, 10:36 AM |
|
You need to select the @@Identity from the db. In the code below the NewIdent var contains the last identity column value
for the connection.
In the <Form Name>_DataSource_AfterExecuteInsert event. Put the following code.
Dim rsIdent , NewIdent
Set rsIdent = DB<Connection Name>.Execute("SELECT @@IDENTITY As intIdent")
If Not rsIdent.EOF Then
NewIdent = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
"hfshultz" <hfshultz@forum.codecharge> wrote in messagenews:64006c4bbea28e@news.codecharge.com...
> I have a form with the Primary key as an autonumber using ASP 3.0 code on a SQL Server backend. When the new record is
created, I want the return page to be the non-editable (all labels) version of the page I have created by having it pass the
new primary key from the first page to the non-editable second page confirming the entry. IE, I create a record that gets a
number of 10 and then opens the second page where Primary key=10.
>
> I've seen code snippets that add one to the max of the primary key records but this isn't going to work for me since there
will be up to 10 people entering information at a time.
>
> Any ideas?
>
> Thanks for your help!
> ~Frank
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
hfshultz
Posts: 17
|
Posted: 01/15/2004, 12:46 PM |
|
Thanks for your quick response. I tried doing this but it's not working. My code is as follows:
Function Tickets_DataSource_AfterExecuteInsert() 'Tickets_DataSource_AfterExecuteInsert @2-F6BCAE66
'Custom Code @209-73254650
Dim rsIdent , NewIdent
Set rsIdent = DBhddb.Execute("SELECT @@IDENTITY As intIdent")
If Not rsIdent.EOF Then
NewIdent = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
'End Custom Code
In my next page, I have the "Where" section of the record query set where TicketID equals the NewIdent expression. I am getting an error on that page: "Variable is undefined: 'NewIdent'"
What am I doing wrong?
|
|
|
peterr
Posts: 5971
|
Posted: 01/15/2004, 1:32 PM |
|
Please try defining your variables separately.
Dim rsIdent
Dim NewIdent
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
Robert Rodgers
|
Posted: 01/15/2004, 3:37 PM |
|
The scope of NewIdent is local to that function. You need to move the Declaration of NewIdent out of the function. Move it
to the top of the Events asp and it should be available to where you need it.
rob
"hfshultz" <hfshultz@forum.codecharge> wrote in messagenews:64006fc082bb81@news.codecharge.com...
> Thanks for your quick response. I tried doing this but it's not working. My code is as follows:
>
> Function Tickets_DataSource_AfterExecuteInsert() 'Tickets_DataSource_AfterExecuteInsert @2-F6BCAE66
>
> 'Custom Code @209-73254650
> Dim rsIdent , NewIdent
>
> Set rsIdent = DBhddb.Execute("SELECT @@IDENTITY As intIdent")
> If Not rsIdent.EOF Then
> NewIdent = CCGetValue(rsIdent,"intIdent")
> End IF
>
> Set rsIdent = Nothing
> 'End Custom Code
>
> In my next page, I have the "Where" section of the record query set where TicketID equals the NewIdent expression. I am
getting an error on that page: "Variable is undefined: 'NewIdent'"
>
> What am I doing wrong?
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
Don Safar
|
Posted: 01/15/2004, 6:26 PM |
|
If you are going to a different page, you will need to set a session
variable. Then change the type in query builder to session in the receiving
page.
Dim rsIdent
Set rsIdent = DB<Connection Name>.Execute("SELECT @@IDENTITY As intIdent")
If Not rsIdent.EOF Then
session("NewIdent") = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
"hfshultz" <hfshultz@forum.codecharge> wrote in message
news:64006fc082bb81@news.codecharge.com...
> Thanks for your quick response. I tried doing this but it's not working.
My code is as follows:
>
> Function Tickets_DataSource_AfterExecuteInsert()
'Tickets_DataSource_AfterExecuteInsert @2-F6BCAE66
>
> 'Custom Code @209-73254650
> Dim rsIdent , NewIdent
>
> Set rsIdent = DBhddb.Execute("SELECT @@IDENTITY As intIdent")
> If Not rsIdent.EOF Then
> NewIdent = CCGetValue(rsIdent,"intIdent")
> End IF
>
> Set rsIdent = Nothing
> 'End Custom Code
>
> In my next page, I have the "Where" section of the record query set where
TicketID equals the NewIdent expression. I am getting an error on that page:
"Variable is undefined: 'NewIdent'"
>
> What am I doing wrong?
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
David Plude
|
Posted: 01/21/2004, 11:03 AM |
|
I tried the following code but the record still does not display when I get to the new page.
Dim rsIdent
Set rsIdent = DBTravel.Execute("SELECT @@IDENTITY As intIdent")
If Not rsIdent.EOF Then
session("NewIdent") = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
I am not sure what else to try either?
|
|
|
DonB
|
Posted: 01/21/2004, 4:47 PM |
|
You have incorrectly specified the Execute. Use:
Set rsIdent = DBTravel.Connection.Execute("SELECT @@IDENTITY As intIdent")
The above is how I do it. I suspect the way you have it loses the "context"
of the previous INSERT (@@IDENTITY is quite volatile).
--
DonB
http://www.gotodon.com/ccbth
<DavidPlude@forum.codecharge (David Plude)> wrote in message
news:6400ecce80ea56@news.codecharge.com...
> I tried the following code but the record still does not display when I
get to the new page.
>
> Dim rsIdent
>
> Set rsIdent = DBTravel.Execute("SELECT @@IDENTITY As intIdent")
> If Not rsIdent.EOF Then
> session("NewIdent") = CCGetValue(rsIdent,"intIdent")
> End IF
>
> Set rsIdent = Nothing
>
> I am not sure what else to try either?
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
Nicole
Posts: 586
|
Posted: 01/26/2004, 4:35 AM |
|
Hello!
The following modifications of the code are working fine for me. I’m not sure what is missed in David’s code, but I ho[e it can help:
1. as you’re doing
Dim rsIdent
Set rsIdent = DBTravel.Execute("SELECT @@IDENTITY As intIdent")
If Not rsIdent.EOF Then
session("NewIdent") = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
2.Dim rsIdent
Set rsIdent = DBTravel.Execute("SELECT @@IDENTITY As intIdent from table_name")
If Not rsIdent.EOF Then
session("NewIdent") = CCGetValue(rsIdent,"intIdent")
End IF
Set rsIdent = Nothing
3. Dim rsIdent
Set rsIdent = DBTravel.Execute("SELECT @@IDENTITY As intIdent from table_name")
If Not rsIdent.EOF Then
Dim tmp
tmp = CCGetValue(rsIdent,"intIdent")
End IF
session("NewIdent")= tmp
Set rsIdent = Nothing
_________________
Regards,
Nicole |
|
|
hfshultz
Posts: 17
|
Posted: 01/26/2004, 5:18 AM |
|
Finally got this working. I had to use the Session variable in my custom insert as the primary key as well to get it to save correctly when changes were made to the second page displayed.
Thanks for all your help everyone, I really appreciate it!
|
|
|