How can i add a value to a row if column value is a certain value ? RRS feed

  • Question

  • User1253338400 posted

    I have 2 tables. One has the schema which, hence column types and names also a column id.
    The second has the index (which is the column id) and column value . So how can i add the value from the second table to the correct column value of the new row in the first table ?
    So if i havea table like

    Name Email Addr
    Bob bob@.. addr st

    Now in the secon table i have an id with the value
    The id corresponds to the column.
    So i want to read that id and make sure when i create the row to add the data to the correct cell ?
    Is it a linq expression that can link the 2 ?

    Sunday, August 4, 2019 9:18 PM


  • User288213138 posted

    Hi robby32,

    According to your description, I couldn’t understand your requirement clearly.

    Do you mean you want to insert value from table2 into table1 by linq?

    If this is your requirement, I suggest you could try to use linq to sql as below code:

    SampleDataContext linq = new SampleDataContext();    
                var str = from Test2 in linq.Test2
                          select Test2;
                foreach (var val in str)    
                    Test1 t1 = new Test1();
                    t1.Id = Convert.ToInt2(val.Id);

    More details about how to use linq to sql, you could refer to this link: Linq to Sql

    If I misunderstand your requirement, please post more details information about your requirement.

    Best regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 5, 2019 7:27 AM