none
Dynamically select and update a column value in LINQ resultset RRS feed

  • Question

  • hi, I have a scenario in which there exists a LINQ resultset; I used the following query

    var stockDetails = from d in db.BloodBanks
    where d
    .bbUserName == Session["username"].ToString()
    select d;

    Now I want to use this resultset and update a column's value. The column is being selected dynamically via a string variable.

    The code which I am trying to use is:

    foreach (BloodBank b in stockDetails)
    {
    b
    .<--column name from string variable--> = TextBox1.Text;
    }

    Please help me out here as to how do I achieve this.


    Piyush
    Sunday, May 15, 2011 3:15 AM

Answers

  • Hey,Piyush

        System.Reflection.PropertyInfo propertyInfo=b.GetType().GetProperty("username");  

        propertyInfo.SetValue(obj, TextBox1.Text,null);  

     


    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Edited by Tim Tang Sunday, May 15, 2011 7:14 AM e
    • Proposed as answer by Albin Abel Sunday, May 15, 2011 8:03 AM
    • Marked as answer by Piyush Paliwal Monday, May 16, 2011 11:19 AM
    Sunday, May 15, 2011 7:13 AM