Selecting a number out of a counter table and updating by 1 RRS feed

  • Question

  • I want to pull a counter value out of a table that contains integers (counters) for tables in my application, then update that table by one number, so that the next select from that table will get a higher number.  I'm only doing this to support the legacy front-end to this application, but I still need to do it.  I tried writing the LINQ queries as noted in the Advanced LightSwitch: Writing Queries in LightSwitch Code, http://blogs.msdn.com/b/lightswitch/archive/2011/10/03/advanced-lightswitch-writing-queries-in-lightswitch-code.aspx#comments, but I always get zero results.  The table only has two columns, table_name, which is the table I am pulling the counter for and table_key, which has the integer that acts as the counter for that table.  The table's name is key.  So my question is, what is the proper way to simply select a single value out of a table, then update it?  Here are some of my valiant attempts at a select statement:

    Dim keys = From k In Me.DataWorkspace.timetrakData.KEYS Where k.TABLE_NAME = ObjKey Select k
    Dim keys = From k In Me.Application.CreateDataWorkspace.timetrakData.KEYS Where k.TABLE_NAME = ObjKey Select k
    Dim ikeys = From k In Me.DataWorkspace.timetrakData.KEYS Select k 'Where k.TABLE_NAME = ObjKey Select k



    Tuesday, April 2, 2013 3:44 AM

All replies

  • OK, I got the query to work.  Not sure why it wasn't working previously, it seems easy enough now.  So how do I perform an update?  Here is my query:

    Dim topKeyList = Me.DataWorkspace.timetrakData.KEYS.Where(Function(o) o.TABLE_NAME = ObjKey).FirstOrDefault()

    I actually have this in a function that I can pass the table name in and get any key.  The field I want to update is KEY_VALUE

    so, like KEY_VALUE = KEY_VALUE + 1

    The topKeyList variable doesn't seem to have any ability to update the row I selected. 



    Tuesday, April 2, 2013 4:51 AM
  • Simply updating the column updates the db record without explicitly using an update statement. 



    Tuesday, April 2, 2013 5:18 AM