Create a simple data application by using ADO.NET. 19 minutes to read. Contributors.
Create a simple data application by using ADO.NET.; 19 minutes to read Contributors. All; In this article. When you create an application that manipulates data in a database, you perform basic tasks such as defining connection strings, inserting data, and running stored procedures. Aug 7, 2017 - The.NET Core is available for Linux and MacOS (in addition to Windows). Microsoft now provides Visual Studio Community for free.
In this article When you create an application that manipulates data in a database, you perform basic tasks such as defining connection strings, inserting data, and running stored procedures. By following this topic, you can discover how to interact with a database from within a simple Windows Forms 'forms over data' application by using Visual C# or Visual Basic and ADO.NET. All.NET data technologies—including datasets, LINQ to SQL, and Entity Framework—ultimately perform steps that are very similar to those shown in this article.
This article demonstrates a simple way to get data out of a database in a fast manner. If your application needs to modify data in non-trivial ways and update the database, you should consider using Entity Framework and using data binding to automatically sync user interface controls to changes in the underlying data.
Important To keep the code simple, it doesn't include production-ready exception handling. Prerequisites To create the application, you'll need:.
Visual Studio. SQL Server Express LocalDB. If you don't have SQL Server Express LocalDB, you can install it from the. This topic assumes that you're familiar with the basic functionality of the Visual Studio IDE and can create a Windows Forms application, add forms to the project, put buttons and other controls on the forms, set properties of the controls, and code simple events. If you aren't comfortable with these tasks, we suggest that you complete the topic before you start this walkthrough. Set up the sample database Create the sample database by following these steps:.
In Visual Studio, open the Server Explorer window. Right-click on Data Connections and choose Create New SQL Server Database. In the Server name text box, enter (localdb) mssqllocaldb. In the New database name text box, enter Sales, then choose OK.
The empty Sales database is created and added to the Data Connections node in Server Explorer. Right-click on the Sales data connection and select New Query. A query editor window opens.
Copy the to your clipboard. Paste the T-SQL script into the query editor, and then choose the Execute button. After a short time, the query finishes running and the database objects are created. The database contains two tables: Customer and Orders. These tables contain no data initially, but you can add data when you run the application that you'll create. The database also contains four simple stored procedures. Create the forms and add controls.
Create a project for a Windows Forms application, and then name it SimpleDataApp. Visual Studio creates the project and several files, including an empty Windows form that's named Form1. Add two Windows forms to your project so that it has three forms, and then give them the following names:. Navigation. NewCustomer. FillOrCancel. For each form, add the text boxes, buttons, and other controls that appear in the following illustrations.
For each control, set the properties that the tables describe. Note The group box and the label controls add clarity but aren't used in the code.