Книги автора: C# 2008 Programmer
Книга: C# 2008 Programmer
Updating Rows
Updating Rows
Updating rows using LINQ to SQL is straightforward — you retrieve the record you need to modify:
DataClasses1DataContext database = new DataClasses1DataContext();
title bookTitle = (from t in database.titles
where (t.title_id == "BU5555")
select t).Single();
The Single()
method returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
Modify the field you want to change:
bookTitle.title1 = "How to Motivate Your Staff";
And submit the changes using the SubmitChanges()
method:
database.SubmitChanges();
The query can alternatively be written using the method syntax, like this:
title bookTitle =
database.titles.Single(t => t.title_id == "BU5555");
Оглавление статьи/книги
Похожие страницы
- Inserting New Rows
- Updating Existing Records—Another Use for WHERE
- Updating Win API Tutorial
- Системные переменные ROWS_AFFECTED, GDSCODE, SQLCODE, TRANSACTIONJD, CONNECTIONJD
- Updating and flushing your tables
- Browsing the Internet
- 13.3. cbrowser
- Browsing and Manipulating Bindery Data
- Tabbed Browsing, Sort Of
- Updating deployed software
- Updating DHCP statistics
- Viewing and updating DNS records