none
Use of Me.Save to save partial dataset

    Pregunta

  • Defined a New Data Screen with a attached dataset. Only a subset of the data need to be entered in the New Data Screen. The data I want to save using a separate Save Data button on the screen and not the general Save button (made invisible to users). The code I used is:

    Private Sub SaveData_Execute()
    Me.Save()
    End Sub

    According to my info Me.Save() should only save screen data but I get validation errors for all elements of the whole dataset that are not entered through the screen.

    What is a solution to get this working properly?

    Thanks for your appreciated feedback.

     

     

     
    martes, 11 de octubre de 2011 8:04

Respuestas

Todas las respuestas

  • John,

    >> but I get validation errors for all elements of the whole dataset that are not entered through the screen.

    What validation errors are you getting? Do these relate to data elements that have been added programatically?

    As you've discovered, Me.Save saves all changes that exist in the 'change set'.

    The key to partially saving changes is to make the partial changes in a new DataWorkspace. Here's the code that you would use to create a new DataWorkspace.

     

    Dim wks As New DataWorkspace
    Dim cust = wks.ApplicationData.Customers.AddNew()
    
    cust.Firstname = "Tim"
    wks.ApplicationData.SaveChanges()
    

    Tim

    martes, 11 de octubre de 2011 8:53
  • Sounds like you have non-nullable fields that you're not entering a value for.

    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    martes, 11 de octubre de 2011 11:15
  • Hi Tim

    Hi Yann

    thanks a lot for help. First I checked if my dataset contains non-nullable fields through the server explorer. With the exception of the primary key of course, all data elements have got the "Allow Null" box ticked.

    I tried Tim's solution. I am still getting validation errors, apparently for each data element not entered through screen data capturing (no data programmatically added). The error screen is a small screen with the name of New data screen on top and reading: "A value is required". The error screen pops-up a number of times.

    In Tim's suggested code line "Dim cust = wks.ApplicationData.Customers.AddNew()" I had to use the name of the whole dataset which is in my case called ClientsSet.

    Might the problem be related to the Save pipeline in a sense that SaveChanges is called to early before LS "sees" the data entered? Although I enter the data first and then hit the Save Data button.

     

    Thanks again for your appreciated thoughts.

    John

    martes, 11 de octubre de 2011 22:08
  • Kia Ora John! (hello, in Maori, in case anyone's wondering, lol)

    Are there any 1-Many related tables? If so, the navigation properties need to be set before you can save a record.

    Why are you trying to do something "different" from what LS was *designed* to do? (not criticising, just trying to understand)


    Yann

    (plus ça change, plus c'est la même chose!)

    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, remember to "Mark as Answer".

    This will help people find the answers that they're looking for more quickly.

    miércoles, 12 de octubre de 2011 0:59
  • Kia Ora to you, Yann! Yes, the app I am trying to build does include a few One-Many tables. How can navigation properties be set prior to saving?

    I am fairly new to LS. The product seemed the right tool for a subject expert without in-depth programming experience. The app I am trying to build is a web based questionnaire to be accessed by clients after they receive login details. Data are captured via a sequence of screens where answers to questions drive the questions on follow-up screens (to avoid non relevant questions). After completion, customised data are extracted to a reporting template in MS Office for further processing.

    Not sure if LS is a suitable tool to develop these kind of apps. What is your view?

    cheers

    John

     

    miércoles, 12 de octubre de 2011 8:37
  • Kia Ora John!

    As an example, say you have a Customer table and an Order table. There's a one to many relationship between Customers and Orders.

    If you're creating a screen for entering new orders, the customer navigation property can be set using code like this: 

    Me.OrderProperty.Customer = Me.DataWorkspace.ApplicationData.Customers_SingleOrDefault(54)
    
    

    In this example, the OrderProperty.Customer is the navigation property and the SingleOrDefault method returns an existing customer with an ID of 54.

    http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/05a4c614-a492-423e-95d0-b35579413c65

    Hope that's of some help.

    Tim

    miércoles, 12 de octubre de 2011 8:59