Retrieve Data Easily
ADO.NET makes data binding easier and more powerful, using Web Forms and Windows Forms.
by Andrew J. Brust
Probably the hardest thing about learning the .NET platform is knowing where to begin. For my money, knowing how to create data access application code is a top priority. So understanding the basics of programming ADO.NET, the successor to ActiveX Data Objects (ADO), would seem a decent place to start.
|
Technology Toolbox
VB.NET, SQL Server 2000, ASP.NET, XML
|
But studying ADO.NET in isolation isn't enough. You need to understand not only the ADO.NET object model, but how to use that object model from Web Forms (ASP.NET) and Windows Forms applications, in Visual Basic .NET and Visual Studio .NET. In this article, you'll learn the basics of ADO.NET in the context of Web Forms and Windows Forms data binding, and understand how to do data binding using the wizards and designers in VS and from "scratch" using only code (see the sidebar, "What You Need to Know").
First, I'll show you how to build a form with data-bound controls, step by step. Later, I'll examine Windows- and Web-based code that I provide for you in the downloadable sample applications for this article. The sample download includes a fully built version of the form whose step-by-step construction I cover in this article.
The most straightforward place to use ADO.NET and data binding is in a Windows Forms application; once you're comfortable there, you can attack something similar in a Web Forms application. So, start by creating a simple Windows Form that allows you to browse the contents of the Customers table in SQL Server's Northwind database. If you don't have access to SQL Server with Northwind on it, make sure you feel comfortable substituting certain of my actions with ones appropriate for your server and database.
First, open VS.NET and create a new Visual Basic Windows Application project. Rename the default form frmDesignTimeCoded, and change the startup object accordingly by right-clicking on the Project's node in the Solution Explorer, selecting Properties, and making the change. Next, set the form's Text property to Design Time Test. Now click on the Data tab in the Toolbox window and drag a SQLDataAdapter object onto the form, which causes the Data Adapter Configuration Wizard to appear. Click on Next from the initial frame, then specify a data connection that points to the Northwind database on your SQL Server. If you've never set up a connection to Northwind inside VS.NET, you need to hit the New Connection button and fill out the Data Link dialog to create one (see Figure 1).
Back to top
|