RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


.NET Basics for the Database Developer: Take the Plunge : Page 3

This short introduction to .NET shows Access and SQL Server developers how to use a development tool to create connections to data and a user interface to manipulate that data.


Designing a Form

After you've established a connection and retrieved data, you'll want to display that data. VB Express offers form objects similar to MS Access. To display data from Northwind's Products table, do the following:
  1. Click the Data Sources tab.
  2. Click the Form1 tab (if necessary) and drag the Products table from the Data Sources tab to Form1 in Form Designer. VB Express will generate a DataGridView control and name it accordingly, using the selected item's name. Figure 10 shows the resulting form and grid after being resized to show most of the fields. In addition, VB Express adds several components to the components tray (below the form).
  3. Press F5 to run the application and display data (see Figure 11).

    Figure 10. A Control to Display the Data: Here is the resulting form and grid resized to show most of the fields.
    Figure 11. Pressing F5 Runs the Application: Press F5 to run the application and display data.

With just a few clicks, you've displayed data from a foreign data source! And it gets better, because the form behaves like any other Windows form.

Use the navigational tools at the top to perform basic tasks such as inserting, deleting, and modifying records. However, if you modify data, you must also click Save Data to update the actual data source via the connection. Without writing a single line of code yourself, you connected to a data source and displayed it, thanks to .NET.

If you're familiar with MS Access, a lot of what you just did might seem familiar. MS Access provides wizards that do a lot of work for you. However, like MS Access, VB Express wizards aren't always the best route to creating the most efficient .NET application. They are used here just to get you started.

Deploying the Project

During the development process, .NET created an .exe file, which you can distribute to other users. By default, .NET stores a project's .exe file in that project file's folder as follows:

C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\

Be sure to make adjustments for your system. Distribute the project's .exe file and instruct the recipient to double-click it to get started. As long as the recipient has .NET and access to the data source using the same path, the .exe file will work.

Wizards Aren't Always the Way

Now that you've started your journey through .NET, it's time to start thinking like a .NET developer and less like an Access or even a SQL Server developer. The example in this article allowed wizards to connect a simple project to a data source and quickly display that data. Wizards, though helpful, aren't always the best option however. In .NET, you can create a custom version of the control with all the desired presets (such as row height, colors, borders, and so on) and then use your custom control to provide a consistent user interface.

Alternatively, you could build a typed dataset that doesn't rely on a direct database connection. Remember how the example .exe file is limited to a specific data source? Using a typed dataset, the user can switch the connection via the user interface. The good news for .NET beginners is that providing all that extra functionality is easy.

Susan Sales Harkins is an independent consultant and the author of several articles and books on database technologies.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date