DetailsView Insert

R

RadioSignal

After a successful DetailsView SQL INSERT of a row with an autogenerated
IDENTITY column key, I'd like to re-display the new database record back to
the user but the key returned in the DetailsView ItemInserted Event args is
NULL. How do I obtain the new key for the confirmation SELECT?
 
S

Steven Cheng[MSFT]

Hi Radio,

Welcome to MSDN newsgroup.
From your description, you're using DetailsView to display data and
inserting data. When you inserting some datas in DetailsView(which has a
autogenerated column in db), you're wondering how to get the autogenerated
primary key(identity), yes?

Based on my research, the DetailsView's Inserting event didn't indicate
that it'll return the updated(autogenerated field)'s value.
However,according to the current BETA document the SqlDataSource's Inserted
event seems provide such output value, you can refer to the following
document:

#SqlDataSourceStatusEventArgs Class (System.Web.UI.WebControls)
http://msdn2.microsoft.com/library/z452ftck(en-us,vs.80).aspx

Also, for detailsView, you can rebind the the DetaislView from teh
datasource which will requery the records with the updated one which
contains the pk field.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)




--------------------
| Thread-Topic: DetailsView Insert
| thread-index: AcWeqc/mMR9HQTUKS72+gH5yG65XLQ==
| X-WBNR-Posting-Host: 192.85.47.2
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| Subject: DetailsView Insert
| Date: Thu, 11 Aug 2005 12:21:02 -0700
| Lines: 4
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10401
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| After a successful DetailsView SQL INSERT of a row with an autogenerated
| IDENTITY column key, I'd like to re-display the new database record back
to
| the user but the key returned in the DetailsView ItemInserted Event args
is
| NULL. How do I obtain the new key for the confirmation SELECT?
|
 
R

RadioSignal

Thank you Steven.

Yes, I want to get either the autogenerated key or some other way to echo
the newly inserted DetailsView record back to the user. We shouldn't require
the user to page through a table of records to find the row he just inserted.

I tried your suggestion of using the SqlDataSource's Inserted event, but I
only received the updated parameters from the parameter list which I supplied
in the DetailsView INSERT request, such as @LastName, @FirstName etc. I do
not receive the desired @NameID key. I also cannot supply the @NameID as a
parameter since this will error the INSERT on an auto generated field.

I could of course supply a new DetailsView querry based upon other non-key
fields from the Inserted record, but that requires the database to hunt
through who knows how many rows to find something that we should already know
how to retrieve.

I was considering a re-querry to the database for the last key created on
this table using an IDENT_CURRENT function, but I'm not sure how to do that
in this context.
 
S

Steven Cheng[MSFT]

Hi Radio,

Thanks for your response. En, after some local tests in the beta2
enviornment, I think you're right. The .NET SqlDataSource's Inserted event
implementation only return the updated parameters which is supplied before
executing the command, so for the autogenerated ID(which isn't presupplied
) , it won't be returned back.
Currently my opinion for such scenario would be use a custom sqlcommand to
execute such insert command separatly, thus we can append a sqlstatement
which query the IDENT_CURRENT after executing the insert statement. This
would be rather more flexible.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Thread-Topic: DetailsView Insert
| thread-index: AcWfX/5P12wGjBZbQC2S9aL/yRX4Rg==
| X-WBNR-Posting-Host: 24.74.0.57
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: DetailsView Insert
| Date: Fri, 12 Aug 2005 10:05:08 -0700
| Lines: 91
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10418
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you Steven.
|
| Yes, I want to get either the autogenerated key or some other way to echo
| the newly inserted DetailsView record back to the user. We shouldn't
require
| the user to page through a table of records to find the row he just
inserted.
|
| I tried your suggestion of using the SqlDataSource's Inserted event, but
I
| only received the updated parameters from the parameter list which I
supplied
| in the DetailsView INSERT request, such as @LastName, @FirstName etc. I
do
| not receive the desired @NameID key. I also cannot supply the @NameID as
a
| parameter since this will error the INSERT on an auto generated field.
|
| I could of course supply a new DetailsView querry based upon other
non-key
| fields from the Inserted record, but that requires the database to hunt
| through who knows how many rows to find something that we should already
know
| how to retrieve.
|
| I was considering a re-querry to the database for the last key created on
| this table using an IDENT_CURRENT function, but I'm not sure how to do
that
| in this context.
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Radio,
| >
| > Welcome to MSDN newsgroup.
| > From your description, you're using DetailsView to display data and
| > inserting data. When you inserting some datas in DetailsView(which has
a
| > autogenerated column in db), you're wondering how to get the
autogenerated
| > primary key(identity), yes?
| >
| > Based on my research, the DetailsView's Inserting event didn't indicate
| > that it'll return the updated(autogenerated field)'s value.
| > However,according to the current BETA document the SqlDataSource's
Inserted
| > event seems provide such output value, you can refer to the following
| > document:
| >
| > #SqlDataSourceStatusEventArgs Class (System.Web.UI.WebControls)
| > http://msdn2.microsoft.com/library/z452ftck(en-us,vs.80).aspx
| >
| > Also, for detailsView, you can rebind the the DetaislView from teh
| > datasource which will requery the records with the updated one which
| > contains the pk field.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | Thread-Topic: DetailsView Insert
| > | thread-index: AcWeqc/mMR9HQTUKS72+gH5yG65XLQ==
| > | X-WBNR-Posting-Host: 192.85.47.2
| > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| > | Subject: DetailsView Insert
| > | Date: Thu, 11 Aug 2005 12:21:02 -0700
| > | Lines: 4
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10401
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | After a successful DetailsView SQL INSERT of a row with an
autogenerated
| > | IDENTITY column key, I'd like to re-display the new database record
back
| > to
| > | the user but the key returned in the DetailsView ItemInserted Event
args
| > is
| > | NULL. How do I obtain the new key for the confirmation SELECT?
| > |
| >
| >
|
 
C

clintonG

I've been trying to learn these new controls myself. The autogenerated ID is
in the control tree hierarchy which can be observed using the Trace page
directive. The generated ID can literally be passed as an argument in code
as it is used in the ViewState. Depending where 'your' control is in the
hierarchy any further addition of controls to the page however can reorder
the autogenerated hierarchy.


<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/


Steven Cheng said:
Hi Radio,

Thanks for your response. En, after some local tests in the beta2
enviornment, I think you're right. The .NET SqlDataSource's Inserted event
implementation only return the updated parameters which is supplied before
executing the command, so for the autogenerated ID(which isn't presupplied
) , it won't be returned back.
Currently my opinion for such scenario would be use a custom sqlcommand to
execute such insert command separatly, thus we can append a sqlstatement
which query the IDENT_CURRENT after executing the insert statement. This
would be rather more flexible.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Thread-Topic: DetailsView Insert
| thread-index: AcWfX/5P12wGjBZbQC2S9aL/yRX4Rg==
| X-WBNR-Posting-Host: 24.74.0.57
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: DetailsView Insert
| Date: Fri, 12 Aug 2005 10:05:08 -0700
| Lines: 91
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10418
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you Steven.
|
| Yes, I want to get either the autogenerated key or some other way to
echo
| the newly inserted DetailsView record back to the user. We shouldn't
require
| the user to page through a table of records to find the row he just
inserted.
|
| I tried your suggestion of using the SqlDataSource's Inserted event, but
I
| only received the updated parameters from the parameter list which I
supplied
| in the DetailsView INSERT request, such as @LastName, @FirstName etc. I
do
| not receive the desired @NameID key. I also cannot supply the @NameID as
a
| parameter since this will error the INSERT on an auto generated field.
|
| I could of course supply a new DetailsView querry based upon other
non-key
| fields from the Inserted record, but that requires the database to hunt
| through who knows how many rows to find something that we should already
know
| how to retrieve.
|
| I was considering a re-querry to the database for the last key created
on
| this table using an IDENT_CURRENT function, but I'm not sure how to do
that
| in this context.
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Radio,
| >
| > Welcome to MSDN newsgroup.
| > From your description, you're using DetailsView to display data and
| > inserting data. When you inserting some datas in DetailsView(which has
a
| > autogenerated column in db), you're wondering how to get the
autogenerated
| > primary key(identity), yes?
| >
| > Based on my research, the DetailsView's Inserting event didn't
indicate
| > that it'll return the updated(autogenerated field)'s value.
| > However,according to the current BETA document the SqlDataSource's
Inserted
| > event seems provide such output value, you can refer to the following
| > document:
| >
| > #SqlDataSourceStatusEventArgs Class (System.Web.UI.WebControls)
| > http://msdn2.microsoft.com/library/z452ftck(en-us,vs.80).aspx
| >
| > Also, for detailsView, you can rebind the the DetaislView from teh
| > datasource which will requery the records with the updated one which
| > contains the pk field.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | Thread-Topic: DetailsView Insert
| > | thread-index: AcWeqc/mMR9HQTUKS72+gH5yG65XLQ==
| > | X-WBNR-Posting-Host: 192.85.47.2
| > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| > | Subject: DetailsView Insert
| > | Date: Thu, 11 Aug 2005 12:21:02 -0700
| > | Lines: 4
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10401
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | After a successful DetailsView SQL INSERT of a row with an
autogenerated
| > | IDENTITY column key, I'd like to re-display the new database record
back
| > to
| > | the user but the key returned in the DetailsView ItemInserted Event
args
| > is
| > | NULL. How do I obtain the new key for the confirmation SELECT?
| > |
| >
| >
|
 
R

RadioSignal

Thank you, Clinton. It may take some time for me to increase my level of
understanding enough to be able to utilize your comments, but I knew that
information must be in there somewhere. I was able to follow Steven's
suggestion by creating a stored procedure for the INSERT. I follow the INSERT
command with a SELECT based upon the IDENT_CURRENT value. This worked well
and allowed me to display the inserted record back to the user in the
DetailsView control.

clintonG said:
I've been trying to learn these new controls myself. The autogenerated ID is
in the control tree hierarchy which can be observed using the Trace page
directive. The generated ID can literally be passed as an argument in code
as it is used in the ViewState. Depending where 'your' control is in the
hierarchy any further addition of controls to the page however can reorder
the autogenerated hierarchy.


<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/


Steven Cheng said:
Hi Radio,

Thanks for your response. En, after some local tests in the beta2
enviornment, I think you're right. The .NET SqlDataSource's Inserted event
implementation only return the updated parameters which is supplied before
executing the command, so for the autogenerated ID(which isn't presupplied
) , it won't be returned back.
Currently my opinion for such scenario would be use a custom sqlcommand to
execute such insert command separatly, thus we can append a sqlstatement
which query the IDENT_CURRENT after executing the insert statement. This
would be rather more flexible.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Thread-Topic: DetailsView Insert
| thread-index: AcWfX/5P12wGjBZbQC2S9aL/yRX4Rg==
| X-WBNR-Posting-Host: 24.74.0.57
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: DetailsView Insert
| Date: Fri, 12 Aug 2005 10:05:08 -0700
| Lines: 91
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10418
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you Steven.
|
| Yes, I want to get either the autogenerated key or some other way to
echo
| the newly inserted DetailsView record back to the user. We shouldn't
require
| the user to page through a table of records to find the row he just
inserted.
|
| I tried your suggestion of using the SqlDataSource's Inserted event, but
I
| only received the updated parameters from the parameter list which I
supplied
| in the DetailsView INSERT request, such as @LastName, @FirstName etc. I
do
| not receive the desired @NameID key. I also cannot supply the @NameID as
a
| parameter since this will error the INSERT on an auto generated field.
|
| I could of course supply a new DetailsView querry based upon other
non-key
| fields from the Inserted record, but that requires the database to hunt
| through who knows how many rows to find something that we should already
know
| how to retrieve.
|
| I was considering a re-querry to the database for the last key created
on
| this table using an IDENT_CURRENT function, but I'm not sure how to do
that
| in this context.
|
|
| "Steven Cheng[MSFT]" wrote:
|
| > Hi Radio,
| >
| > Welcome to MSDN newsgroup.
| > From your description, you're using DetailsView to display data and
| > inserting data. When you inserting some datas in DetailsView(which has
a
| > autogenerated column in db), you're wondering how to get the
autogenerated
| > primary key(identity), yes?
| >
| > Based on my research, the DetailsView's Inserting event didn't
indicate
| > that it'll return the updated(autogenerated field)'s value.
| > However,according to the current BETA document the SqlDataSource's
Inserted
| > event seems provide such output value, you can refer to the following
| > document:
| >
| > #SqlDataSourceStatusEventArgs Class (System.Web.UI.WebControls)
| > http://msdn2.microsoft.com/library/z452ftck(en-us,vs.80).aspx
| >
| > Also, for detailsView, you can rebind the the DetaislView from teh
| > datasource which will requery the records with the updated one which
| > contains the pk field.
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| >
| > --------------------
| > | Thread-Topic: DetailsView Insert
| > | thread-index: AcWeqc/mMR9HQTUKS72+gH5yG65XLQ==
| > | X-WBNR-Posting-Host: 192.85.47.2
| > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| > | Subject: DetailsView Insert
| > | Date: Thu, 11 Aug 2005 12:21:02 -0700
| > | Lines: 4
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl
| > microsoft.public.dotnet.framework.aspnet.webcontrols:10401
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > |
| > | After a successful DetailsView SQL INSERT of a row with an
autogenerated
| > | IDENTITY column key, I'd like to re-display the new database record
back
| > to
| > | the user but the key returned in the DetailsView ItemInserted Event
args
| > is
| > | NULL. How do I obtain the new key for the confirmation SELECT?
| > |
| >
| >
|
 
S

Steven Cheng[MSFT]

Thanks for your followup Radio,

Glad that you've got the thing work now. Also, if there're any further
question or anything we can help later, please always feel free to post
here.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| Thread-Topic: DetailsView Insert
| thread-index: AcWjX/4/l6QOytnSQoWS82uNkaSoyQ==
| X-WBNR-Posting-Host: 192.85.47.1
| From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: DetailsView Insert
| Date: Wed, 17 Aug 2005 12:15:13 -0700
| Lines: 190
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.webcontrols:10477
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
|
| Thank you, Clinton. It may take some time for me to increase my level of
| understanding enough to be able to utilize your comments, but I knew that
| information must be in there somewhere. I was able to follow Steven's
| suggestion by creating a stored procedure for the INSERT. I follow the
INSERT
| command with a SELECT based upon the IDENT_CURRENT value. This worked
well
| and allowed me to display the inserted record back to the user in the
| DetailsView control.
|
| "clintonG" wrote:
|
| > I've been trying to learn these new controls myself. The autogenerated
ID is
| > in the control tree hierarchy which can be observed using the Trace
page
| > directive. The generated ID can literally be passed as an argument in
code
| > as it is used in the ViewState. Depending where 'your' control is in
the
| > hierarchy any further addition of controls to the page however can
reorder
| > the autogenerated hierarchy.
| >
| >
| > <%= Clinton Gallagher
| > METROmilwaukee (sm) "A Regional Information Service"
| > NET csgallagher AT metromilwaukee.com
| > URL http://metromilwaukee.com/
| > URL http://clintongallagher.metromilwaukee.com/
| >
| >
| > | > > Hi Radio,
| > >
| > > Thanks for your response. En, after some local tests in the beta2
| > > enviornment, I think you're right. The .NET SqlDataSource's Inserted
event
| > > implementation only return the updated parameters which is supplied
before
| > > executing the command, so for the autogenerated ID(which isn't
presupplied
| > > ) , it won't be returned back.
| > > Currently my opinion for such scenario would be use a custom
sqlcommand to
| > > execute such insert command separatly, thus we can append a
sqlstatement
| > > which query the IDENT_CURRENT after executing the insert statement.
This
| > > would be rather more flexible.
| > >
| > > Thanks & Regards,
| > >
| > > Steven Cheng
| > > Microsoft Online Support
| > >
| > > Get Secure! www.microsoft.com/security
| > > (This posting is provided "AS IS", with no warranties, and confers no
| > > rights.)
| > >
| > >
| > > --------------------
| > > | Thread-Topic: DetailsView Insert
| > > | thread-index: AcWfX/5P12wGjBZbQC2S9aL/yRX4Rg==
| > > | X-WBNR-Posting-Host: 24.74.0.57
| > > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?=" <[email protected]>
| > > | References: <[email protected]>
| > > <[email protected]>
| > > | Subject: RE: DetailsView Insert
| > > | Date: Fri, 12 Aug 2005 10:05:08 -0700
| > > | Lines: 91
| > > | Message-ID: <[email protected]>
| > > | MIME-Version: 1.0
| > > | Content-Type: text/plain;
| > > | charset="Utf-8"
| > > | Content-Transfer-Encoding: 7bit
| > > | X-Newsreader: Microsoft CDO for Windows 2000
| > > | Content-Class: urn:content-classes:message
| > > | Importance: normal
| > > | Priority: normal
| > > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > > | Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > > | Xref: TK2MSFTNGXA01.phx.gbl
| > > microsoft.public.dotnet.framework.aspnet.webcontrols:10418
| > > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
| > > |
| > > | Thank you Steven.
| > > |
| > > | Yes, I want to get either the autogenerated key or some other way
to
| > > echo
| > > | the newly inserted DetailsView record back to the user. We shouldn't
| > > require
| > > | the user to page through a table of records to find the row he just
| > > inserted.
| > > |
| > > | I tried your suggestion of using the SqlDataSource's Inserted
event, but
| > > I
| > > | only received the updated parameters from the parameter list which I
| > > supplied
| > > | in the DetailsView INSERT request, such as @LastName, @FirstName
etc. I
| > > do
| > > | not receive the desired @NameID key. I also cannot supply the
@NameID as
| > > a
| > > | parameter since this will error the INSERT on an auto generated
field.
| > > |
| > > | I could of course supply a new DetailsView querry based upon other
| > > non-key
| > > | fields from the Inserted record, but that requires the database to
hunt
| > > | through who knows how many rows to find something that we should
already
| > > know
| > > | how to retrieve.
| > > |
| > > | I was considering a re-querry to the database for the last key
created
| > > on
| > > | this table using an IDENT_CURRENT function, but I'm not sure how to
do
| > > that
| > > | in this context.
| > > |
| > > |
| > > | "Steven Cheng[MSFT]" wrote:
| > > |
| > > | > Hi Radio,
| > > | >
| > > | > Welcome to MSDN newsgroup.
| > > | > From your description, you're using DetailsView to display data
and
| > > | > inserting data. When you inserting some datas in
DetailsView(which has
| > > a
| > > | > autogenerated column in db), you're wondering how to get the
| > > autogenerated
| > > | > primary key(identity), yes?
| > > | >
| > > | > Based on my research, the DetailsView's Inserting event didn't
| > > indicate
| > > | > that it'll return the updated(autogenerated field)'s value.
| > > | > However,according to the current BETA document the SqlDataSource's
| > > Inserted
| > > | > event seems provide such output value, you can refer to the
following
| > > | > document:
| > > | >
| > > | > #SqlDataSourceStatusEventArgs Class (System.Web.UI.WebControls)
| > > | > http://msdn2.microsoft.com/library/z452ftck(en-us,vs.80).aspx
| > > | >
| > > | > Also, for detailsView, you can rebind the the DetaislView from teh
| > > | > datasource which will requery the records with the updated one
which
| > > | > contains the pk field.
| > > | >
| > > | > Thanks,
| > > | >
| > > | > Steven Cheng
| > > | > Microsoft Online Support
| > > | >
| > > | > Get Secure! www.microsoft.com/security
| > > | > (This posting is provided "AS IS", with no warranties, and
confers no
| > > | > rights.)
| > > | >
| > > | >
| > > | >
| > > | >
| > > | > --------------------
| > > | > | Thread-Topic: DetailsView Insert
| > > | > | thread-index: AcWeqc/mMR9HQTUKS72+gH5yG65XLQ==
| > > | > | X-WBNR-Posting-Host: 192.85.47.2
| > > | > | From: "=?Utf-8?B?UmFkaW9TaWduYWw=?="
<[email protected]>
| > > | > | Subject: DetailsView Insert
| > > | > | Date: Thu, 11 Aug 2005 12:21:02 -0700
| > > | > | Lines: 4
| > > | > | Message-ID: <[email protected]>
| > > | > | MIME-Version: 1.0
| > > | > | Content-Type: text/plain;
| > > | > | charset="Utf-8"
| > > | > | Content-Transfer-Encoding: 7bit
| > > | > | X-Newsreader: Microsoft CDO for Windows 2000
| > > | > | Content-Class: urn:content-classes:message
| > > | > | Importance: normal
| > > | > | Priority: normal
| > > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
| > > | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > > | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > > | > | Xref: TK2MSFTNGXA01.phx.gbl
| > > | > microsoft.public.dotnet.framework.aspnet.webcontrols:10401
| > > | > | X-Tomcat-NG:
microsoft.public.dotnet.framework.aspnet.webcontrols
| > > | > |
| > > | > | After a successful DetailsView SQL INSERT of a row with an
| > > autogenerated
| > > | > | IDENTITY column key, I'd like to re-display the new database
record
| > > back
| > > | > to
| > > | > | the user but the key returned in the DetailsView ItemInserted
Event
| > > args
| > > | > is
| > > | > | NULL. How do I obtain the new key for the confirmation SELECT?
| > > | > |
| > > | >
| > > | >
| > > |
| > >
| >
| >
| >
|
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top