Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Linq, updating multiple records

SQL Linq, updating multiple records

Scheduled Pinned Locked Moved Database
csharpdatabaselinqtutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I know how to update a single record, but updating multiple records is different. Single

    Dim uTemplate As CRM_JOBS = context.crm_Jobs.Single(Function(m) m.templateName = templateName)
    uTemplate.templateXHTML = sEMT.templateXHTML
    uTemplate.templateID = pValue
    context.SaveChanges()

    I thought of this for multiple records, but items doesn't carry over to the loop. So would I have to project it into something and then save?

    Dim jobs =
    From items In context.crm_Jobs
    Where items.templateName = templateName

    For Each items In jobs
    jobs.templateXHTML = sEMT.templateXHTML
    jobs.templateID = pValue
    Next
    context.SaveChanges()

    [edit] I have this now

    Dim jobs =
    From j In context.crm_Jobs
    Where j.templateName = templateName
    Select j

    For Each j As CRM_JOBS In jobs
    j.templateXHTML = sEMT.templateXHTML
    j.templateID = sEMT.templateID
    Next

    context.SaveChanges()

    Oh that works!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups