原文:http://msdn.microsoft.com/en-us/library/bb399339.aspx
To update a row in the database
-
Query the database for the row to be updated.
-
Make desired changes to member values in the resulting LINQ to SQL object.
-
Submit the changes to the database.
The following example queries the database for order #11000, and then changes the values of ShipName and ShipVia in the resulting Order object. Finally, the changes to these member values are submitted to the database as changes in the ShipName and ShipVia columns.
// Query the database for the row to be updated. var query = from ord in db.Orders where ord.OrderID == 11000 select ord; // Execute the query, and change the column values // you want to change. foreach (Order ord in query) { ord.ShipName = "Mariner"; ord.ShipVia = 2; // Insert any additional changes to column values. } // Submit the changes to the database. try { db.SubmitChanges(); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. }
本文介绍如何使用LINQ to SQL更新数据库中的特定行记录。通过查询指定订单并修改其属性值,最后将更改提交到数据库中。
1337

被折叠的 条评论
为什么被折叠?



