How to directly edit a record in your Microsoft Lightswitch data source?

Whenever there is a requirement to edit records by batch in my Microsoft Lightswitch project I would normally make a grid, and from the grid the records get edited.  But you can edit the records directly using the DataWorkspace object, see the code below.

Dim dw = Me.Application.CreateDataWorkspace
Dim PostedSales = (From s In dw.MyData.Sales
                   Where s.SalesNumber >= Me.SalesNumberStart  AndAlso
                         s.SalesNumber <= Me.SalesNumberEnd).Execute
For Each PostedSalesItem In PostedSales
     PostedSalesItem.Posted = "Yes"
Next
dw.MyData.SaveChanges()

The above code extract a set of record in the Sales table based on a series of Sales Number encoded by the user, then loop through the extracted records and update the Posted property of the table to “Yes”.

If you find this blog helpful, you can make the donation by clicking the Paypal button below.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s