locked
How to retrieve SQL Server Identity column value when row is added by Lightswitch RRS feed

  • Question

  • I think this has been asked before, but darn I can't find it.

    I working with VS2013 on a Lightswitch desktop app.

    If I add a row to a SQL Server table via Lightswitch and the table has an Identity column, how do I find the value of the Identity column for the row I just added? I want to both tell it to the user and be able to retrieve the row later.

    Thanks in advance.

    Wednesday, April 15, 2015 8:57 PM

Answers

All replies

  • // Create a new PhoneCall
    var objPhoneCall = serverContext.DataWorkspace.ApplicationData.PhoneCalls.AddNew();
    
    // Set values
    objPhoneCall.CallType = ddlCallType.SelectedValue;
    objPhoneCall.Description = txtDescription.Text;
    objPhoneCall.PersonCalling = txtPersonCalling.Text;
    objPhoneCall.PhoneNumber = txtPhoneNumber.Text;
    
    // Save changes
    serverContext.DataWorkspace.ApplicationData.SaveChanges();
    
    // Get the ID
    var ID = objPhoneCall.Id; 


    Unleash the Power - Get the LightSwitch 2013 HTML Client / SharePoint 2013 book

    http://LightSwitchHelpWebsite.com

    • Marked as answer by AIBMass Thursday, April 16, 2015 3:12 PM
    Wednesday, April 15, 2015 11:10 PM
  • Duh. Nice of Lightswitch to make it easy.

    Thanks for your time in answering.

    Thursday, April 16, 2015 3:13 PM