Obtaining the Appointment ID after appointment creation

8 posts, 0 answers
  1. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 25 Oct 2007 Link to this post

    Hi,

    very sorry that I am hammering the forum again.  But I have hit a brick wall with regard how to obtain the appointment ID after creation.

    I have got an appointment which is programatically created within the "FormCreating" event (user double clicks the rest of the process is performed by code), this works well. 

    However I need to obtain the appointment ID to pass this value to another datasource.  I have had no sucess with obaining the value,  my thoughts were that to obtain the appointment ID this would be in the "formCreated" event.  But when I debug the page, the event never gets fired even though the "formcreating" event does.

    Am I missing something? How do I obtain the AppointmentID imeditaly after creation?

    Thanks,

    JK

    P.S. Is there any detailed docs on Scheduler (only got help system, not much to go on) so I can review that before posting?
  2. Tim Barton
    Tim Barton avatar
    30 posts
    Member since:
    Apr 2003

    Posted 26 Oct 2007 Link to this post

    Hi JK,

    When I create an event, I create the ID to put in the database.  To get the ID after created you can try e.Appointment.ID or e.ModifiedAppointment.ID if you changed the ID for some reason.

    Tim 

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 28 Oct 2007 Link to this post

    Thanks for your input Tim.
    Unfortunatley, the e.appointmentID does not exist during the formcreating stage as at that point the appointment does not exist ( my code performs an insert appointment command).

    The e.modifedappointmentID workes if your editing a appointment which in this case I am not doing.

    Unless there is another application to e.modifedappointment I am missing?

    Thanks,

    JK
  5. Tim Barton
    Tim Barton avatar
    30 posts
    Member since:
    Apr 2003

    Posted 28 Oct 2007 Link to this post

    Hi JK,

    Doing the creating phase you have to create the ID.  Telerik uses the Guid.NewGuid().ToString() to create the ID in there examples and I use the same method.   How do you created the ID that is put in your datasource when the event is created?

    Thanks,
    Tim
  6. EmpowerIT
    EmpowerIT avatar
    117 posts
    Member since:
    Jun 2007

    Posted 28 Oct 2007 Link to this post

    Are you sure you are not setting e.Cancel to true in the formCreating event?
    If you set this to true, i believe the formCreated event will not fire (because it thinks you are cancelling out of creating a form).

    You will need to keep track of the last appointment you created so that you can retrieve it and check its ID property.

  7. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 29 Oct 2007 Link to this post

    Thanks for the response guys.

    I think i may have worked it out.  But to answer both your questions.

    Tim - I have set the SQL datasource to a identity seed datatype so no intervention is performed on the schedulers part it just gets assigned the next number and since this is on the SQL side (i.e number assignment occurs after/during record creation, I wanted to know how/if the scheduler retrieves this information.  I suspect this is done on the formcreated part which is where I was placing the code (which would not fire)

    Link64 - Feel very embarrassed now.  Your bang on the money,  The last line in the formcreating event is to cancel the creation of the appointment as the rest of my code creates the appointment (it just needs the user to double click to get the appointment underway).  Becuase of this the formcreated event never fires!

    Now I have an understanding of what is going on I suspect I would be able to obtain the ID by performing a rebind (dirty read) to the scheduler as no new call to the DB would be done the last appointment would be the ID number I would require.  So putting the code in the "appointmentcreating" event would recurse through each appointment until the last one (newly created appointment) and then I can assign that number to the other datasource.

    Thanks for both your help.  Must say this is probably the best forum I have ever used everyone is very helpful!

    JK
  8. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 29 Oct 2007 Link to this post

    Hello Jon,

    This is the same answer as in your support ticket, I am duplicating it here for the forum users to see.

    You can use the Inserted event of the SqlDataSource to determine the ID of the newly created record.
    First, you need to modify the insert query:

    InsertCommand="INSERT INTO ServiceHistory(...) VALUES (...); SELECT @NewID = @@IDENTITY" 

    You can change "@@IDENTITY" to "SCOPE_IDENTITY()", if you are using SQL Server.

    Then, add the following parameter to the InsertParameters:

    <asp:Parameter Direction=Output Name="NewID" Type="Int64" /> 

    We can now handle the Inserted event to get the ID of the inserted appointment:

    protected void AppointmentsDataSource_Inserted(object sender, SqlDataSourceStatusEventArgs e)  
    {  
        Int64 newId = (Int64) e.Command.Parameters["@NewID"].Value;  
    }  


    Greetings,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. JK
    JK avatar
    123 posts
    Member since:
    Sep 2007

    Posted 29 Oct 2007 Link to this post

    it is amazing how I always overcomplicate things!

    Thank you so much guys for all your help, at the very least it is expanding my knowledge very quickly :o)

    JK
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017