To connect a WinForms App to a database using an ADO.NET Entity Data Model, you can follow these steps:
- In Visual Studio, create a new C# WinForms App (.NET Framework) project.
- Install the Entity Framework 6 NuGet package by selecting the project node in Solution Explorer, then choosing Project > Manage NuGet Packages. In the NuGet Package Manager, click on the Browse link, search for "EntityFramework", and click Install in the right pane.
- Add a new connection to the Northwind database in Server Explorer by right-clicking on Data Connections and selecting Add Connection. Choose Microsoft SQL Server as the data source, and enter the server name and database file path for your Northwind database. If you're using SQL Server Express, the server name may be in the format "localhost\SQLEXPRESS". Once you've successfully configured the connection information, the database will be added as a node underneath the Data Connections node.
- In the Solution Explorer, right-click on the project node and choose Add > New Item. Select ADO.NET Entity Data Model, enter "NorthwindModel" as the name, and click Add.
- In the Entity Data Model Wizard, select "Generate from database" and click Next. Choose the Northwind database connection you added in step 3, and enter "NorthwindEntities" as the name of the connection string. Click Next, then select the tables you want to include in your model and click Finish.
- You can now use the NorthwindEntities object to query and manipulate data in your WinForms application.
References: