Use the entity of ADO. NET Entity Framework as the data source (with demo program download)-Series 3

Source: Internet
Author: User
This article is ADO. NET Entity Framework Series of articlesArticle 3: continue to demonstrate how to use the entity of ADO. NET Entity Framework as the data source of the data control to easily display data records in the Data Control. ADO. the first two articles of NET Entity Framework are as follows: ADO. NET Entity Framework getting started example wizard (with demo program download) ADO. NET Entity Framework getting started example wizard (with demo program download)-Series 2 first, according to ADO. NET Entity Data Model Wizard to create an EDM file. For more information, see ADO. NET Entity Framework getting started example wizard (with demo program download. 1. Add new data sourceThe procedure is as follows:

Select Add new data source. The data source Configuration Wizard window is displayed. The page is as follows:

Select object as data source type and click Next. On the next page of the wizard, expand the tree node-data model to display all entity classes. Select the entity class for which data source needs to be created, and click Next.

2. Show Data SourceSelect the data menu/show data sources menu to display data sources in the project.

 3.Set the data source created in the previous stepDrag to Windows formForm.By default, a new datagridview control and the navigation Toolbar Control are automatically added to the Windows form. The bindingsource and binding navigation controls are also automatically created, and the preceding two controls are automatically bound to the bindingsource and binding navigation controls. The interface is as follows:

  4. Next Control display data source .Add the following code in Windows form: Private void form1_load (Object sender, eventargs e) {northwindentities = new northwindentities (); customersbindingsource. datasource = northwindentities. MERs MERS ;}

The example program running interface is as follows:

  5. Edit and save dataThe bindingsource component ensures that the editing of the datagridview control is updated to the entity class. After editing, you need to save the updated data to the database. Next, adjust the Enable attribute of save in the navigation toolbar to true. Double-click the Save button and add the following code in the SAVE Click Event: Private void customersbindingnavigatorsaveitem_click (Object sender, eventargs e) {northwindentities. savechanges ();} The savechanges () method is responsible for saving the update of the entity class to the database.

Download the source code of this example project.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.