Working with a Database in C#
- Introduction to ADO.NET
- Connecting to a Database
- Manipulating Data
- Using the Data Form Wizard
See all Sams Teach Yourself on InformIT Programming Tutorials.
You've heard it so many times that it's almost a cliché: This is the information age. Information is data, and managing information means working with databases. Database design is a skill unto itself, and entire books are devoted to database design and management. In this hour, you'll learn the basics of working with a database using ADO.NET, Microsoft's newest database technology. Although high-end solutions are built around advanced database technologies such as Microsoft's SQL Server, the Microsoft Jet database (used by Microsoft Access) is more readily available and easier to learn, so you'll build working examples that use a Jet database.
The highlights of this hour include the following:
Introduction to ADO.NET
Connecting to a database
Creating a DataAdapter
Referencing fields in a DataRow
Adding, editing, and deleting records
Building an ADO.NET example
You'll learn a lot in this hour, but realize that this material is really the tip of the iceberg. Database programming can be, and often is, very complex. This hour is intended to get you writing database code as quickly as possible, but if you plan on doing a lot of database programming, you'll want to consult a dedicated book (or two) on the subject.
Start by creating a new Windows Application named Database Example. Change the name of the default form to fclsMain and set its Text property to Database Example. Next, click the View Code button on the Solution Explorer window to access the form's code, scroll down and locate the procedure Main(), and change the reference of Form1 to fclsMain. Finally, click the Form1.cs tab to return to the form designer.
Introduction to ADO.NET
ADO.NET is the .NET platform's new database technology, and it builds on ADO (Active Data Objects). ADO.NET defines DataSet and DataTable objects that are optimized for moving disconnected sets of data across intranets and Internets, including through firewalls. At the same time, ADO.NET includes the traditional Connection and Command objects, as well as an object called a DataReader that resembles a forward-only, read-only ADO recordset. Together these objects provide the very best performance and throughput for retrieving data from a database.