DetailsView Insert

Discussion in 'ASP .Net Web Controls' started by RadioSignal, Aug 11, 2005.

  1. RadioSignal

    RadioSignal Guest

    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?
    RadioSignal, Aug 11, 2005
    #1
    1. Advertising

  2. 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=?=" <>
    | Subject: DetailsView Insert
    | Date: Thu, 11 Aug 2005 12:21:02 -0700
    | Lines: 4
    | Message-ID: <>
    | 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?
    |
    Steven Cheng[MSFT], Aug 12, 2005
    #2
    1. Advertising

  3. RadioSignal

    RadioSignal Guest

    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=?=" <>
    > | Subject: DetailsView Insert
    > | Date: Thu, 11 Aug 2005 12:21:02 -0700
    > | Lines: 4
    > | Message-ID: <>
    > | 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?
    > |
    >
    >
    RadioSignal, Aug 12, 2005
    #3
  4. 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=?=" <>
    | References: <>
    <>
    | Subject: RE: DetailsView Insert
    | Date: Fri, 12 Aug 2005 10:05:08 -0700
    | Lines: 91
    | Message-ID: <>
    | 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=?=" <>
    | > | Subject: DetailsView Insert
    | > | Date: Thu, 11 Aug 2005 12:21:02 -0700
    | > | Lines: 4
    | > | Message-ID: <>
    | > | 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?
    | > |
    | >
    | >
    |
    Steven Cheng[MSFT], Aug 15, 2005
    #4
  5. RadioSignal

    clintonG Guest

    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[MSFT]" <> wrote in message
    news:...
    > 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=?=" <>
    > | References: <>
    > <>
    > | Subject: RE: DetailsView Insert
    > | Date: Fri, 12 Aug 2005 10:05:08 -0700
    > | Lines: 91
    > | Message-ID: <>
    > | 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=?=" <>
    > | > | Subject: DetailsView Insert
    > | > | Date: Thu, 11 Aug 2005 12:21:02 -0700
    > | > | Lines: 4
    > | > | Message-ID: <>
    > | > | 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?
    > | > |
    > | >
    > | >
    > |
    >
    clintonG, Aug 15, 2005
    #5
  6. RadioSignal

    RadioSignal Guest

    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/
    >
    >
    > "Steven Cheng[MSFT]" <> wrote in message
    > news:...
    > > 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=?=" <>
    > > | References: <>
    > > <>
    > > | Subject: RE: DetailsView Insert
    > > | Date: Fri, 12 Aug 2005 10:05:08 -0700
    > > | Lines: 91
    > > | Message-ID: <>
    > > | 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=?=" <>
    > > | > | Subject: DetailsView Insert
    > > | > | Date: Thu, 11 Aug 2005 12:21:02 -0700
    > > | > | Lines: 4
    > > | > | Message-ID: <>
    > > | > | 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?
    > > | > |
    > > | >
    > > | >
    > > |
    > >

    >
    >
    >
    RadioSignal, Aug 17, 2005
    #6
  7. 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=?=" <>
    | References: <>
    <>
    <>
    <>
    <>
    | Subject: Re: DetailsView Insert
    | Date: Wed, 17 Aug 2005 12:15:13 -0700
    | Lines: 190
    | Message-ID: <>
    | 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/
    | >
    | >
    | > "Steven Cheng[MSFT]" <> wrote in message
    | > news:...
    | > > 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=?=" <>
    | > > | References: <>
    | > > <>
    | > > | Subject: RE: DetailsView Insert
    | > > | Date: Fri, 12 Aug 2005 10:05:08 -0700
    | > > | Lines: 91
    | > > | Message-ID: <>
    | > > | 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=?="
    <>
    | > > | > | Subject: DetailsView Insert
    | > > | > | Date: Thu, 11 Aug 2005 12:21:02 -0700
    | > > | > | Lines: 4
    | > > | > | Message-ID: <>
    | > > | > | 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?
    | > > | > |
    | > > | >
    | > > | >
    | > > |
    | > >
    | >
    | >
    | >
    |
    Steven Cheng[MSFT], Aug 18, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Rich

    Detailsview empty dataset insert

    Justin Rich, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,223
    Justin Rich
    May 19, 2005
  2. Eric Zhao

    Detailsview empty dataset insert

    Eric Zhao, Aug 30, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,890
    Brock Allen
    Aug 30, 2005
  3. cannontrodder
    Replies:
    1
    Views:
    698
    cannontrodder
    Jul 25, 2006
  4. eagle

    Insert & Insert/Repeat buttons in a detailsview

    eagle, Jul 12, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    1,028
    eagle
    Jul 12, 2007
  5. Feege
    Replies:
    0
    Views:
    420
    Feege
    Dec 20, 2005
Loading...

Share This Page