Cannot update record use LINQ RRS feed

  • Question

  • Hi every one,

    I need help. I am doing use LINQ insert, update method. But, I have a problem now. I could not update my record. I don't know why. Could some body help me please?

    My code is:

     using (DataContext.Order db = new DataContext.Order((string)HttpContext.Current.Session["Level"]))

                    var NewOrder = (from MyOrder in db.Orders where MyOrder.Id==TheUserId select MyOrder).First();
                    NewOrder.Name = txtName.Text.Trim();
                    NewOrder.ShipToAddress = txtShipAdd.Text.Trim();
                    NewUser.Email = txtEmail.Text.Trim();

    Thank you.

    Thursday, September 24, 2009 3:45 PM


  • Hi tarim,

    If you run this Linq statement in an Console Application, you can add the sentence ' db.Log = Console.Out;' in your code to output the SQL statement that is translated from your linq statement.  Check the SQL statement to see if the right operation has be executed.

    Generally speaking, you would see 'insert into' key words in the output. But if there's only 'select' SQL statement appearing, the problem is probably that you forgot to set the primary key in your database.

    Feel free to ask more if 'to set the primary key' doesn't solve the problem.

    Best regards,
    Charlie Lee

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhipeng Lee Wednesday, September 30, 2009 1:33 AM
    Friday, September 25, 2009 8:41 AM