DataSource = db.Contacts
This code binds the data source of the BindingSource with the Contacts table, essentially providing the
LINQ.Contact data source with the data it needs.
OK, time to test. Press F5 to compile and run the project. When the form loads, it will automatically load
with data. You can use the navigation arrows on the navigator control (see Figure 15-23) to move between
records, and you can also use the Add and Remove buttons to add new rows and delete existing rows.
If you delete or add a row, is it saved back to the database? No. Why? Remember that behind all of this
is LINQ to SQL. You need to ??????submit changes??™??™ back to the database. Stop the project and select the Save
button on the navigation control. Open the Properties window, and set the Enabled property for the
Save button to True. Next, double-click the Save button to create a Click() event handler for the button.
Then, add the following code:
db.SubmitChanges();
Simple, isn??™t it? Now run the project again, and add and delete data. To verify that data is truly added
and deleted, open a new query window in SQL Server Management Studio and execute the following
T-SQL statement:
SELECT * FROM Person.
Pages:
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488