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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. LINQ
  4. LINQ Loop Function

LINQ Loop Function

Scheduled Pinned Locked Moved LINQ
questiondatabasecsharplinqhelp
2 Posts 2 Posters 3 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.
  • I Offline
    I Offline
    Illegal Operation
    wrote on last edited by
    #1

    Hi, I have a problem. I have a SQL database with 2 tables and in the same database I have created 2 new tables that basically takes the information from the first 2 tables. My question is this: How can I itterate throught the first tables and write that information to the new tables using LINQ to SQL?

    Illegal Operation

    P 1 Reply Last reply
    0
    • I Illegal Operation

      Hi, I have a problem. I have a SQL database with 2 tables and in the same database I have created 2 new tables that basically takes the information from the first 2 tables. My question is this: How can I itterate throught the first tables and write that information to the new tables using LINQ to SQL?

      Illegal Operation

      P Offline
      P Offline
      PunkIsNotDead
      wrote on last edited by
      #2

      try

      MyDataContext dc = new MyDataContext();//the dbml file
      var Table1 = from T in dc.YourTable1
      select T;
      foreach (var Row in Table1)
      {
      dc.ImportingTo Table2 = new dc.ImportingTo();
      Table2.Field1 = Row.Field1;
      Table2.Field2 = Row.Field2;
      Table2.Field3 = Row.Field3;
      Table2.Field4 = Row.Field4;//...etc.
      dc.ImportingTo.InsertOnSubmit(Table2);
      }
      dc.SubmitChanges();

      I think this is the sintax! :-D if you have some problem, let me know! :thumbsup:

      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