locked
How to copy data from one table to another? RRS feed

  • Question

  • User-353733005 posted

    I've two table "main" & "temporary" with the same fields. I want to copy the "temporary" table data to the "main" table & I'm using the entity framework. Is there any way to do that without showing each and every fields in the "main" table or can I clone the "temporary" table data and insert it into the "main" table?

    Thanks in advance.

    Tuesday, May 22, 2018 6:35 AM

Answers

  • User-1768369891 posted

    Shibly

    I've two table "main" & "temporary" with the same fields. I want to copy the "temporary" table data to the "main" table & I'm using the entity framework. Is there any way to do that without showing each and every fields in the "main" table or can I clone the "temporary" table data and insert it into the "main" table?

    As per below URL :- 

    The code would almost be the same as seen below...

    https://www.experts-exchange.com/questions/28933937/Linq-To-SQL-Move-Data-From-One-Table-To-Another.html

    // Create the DataContext object
    DataClasses1DataContext db = new DataClasses1DataContext();
    
    // The value to be used to find the record in TableA
    string name = "SomeValue";
    
    // Query the TableA for the record to be moved
    TableA ta = db.TableAs.Where(tn => tn.Name == name).FirstOrDefault();
    // If the record was found move it
    if( ta != null ) {
        TableB tb = new TableB { Name = ta.Name, Age = ta.Age, ... };
        db.TableBs.InsertOnSubmit(tb);
        db.TableAs.DeleteOnSubmit(ta);
        db.SubmitChanges();
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 22, 2018 6:51 AM