Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 12 - Text Files and String Processing

By Dan Mabbutt, About.com

6 of 10

A System.Data Namespace Example

Intellisense Resolves System.Data

Intellisense Resolves System.Data Reference

Now let's look at another actual example. To illustrate this idea, we're going to use the System.Data namespace - which provides the new ADO.NET data technology.

System.Data is added to Windows applications as a Reference by default in VB.NET.

Adding a namespace to the Reference collection in a project makes the objects in that namespace available to the project. The most visible effect of this is that the Visual Studio "Intellisense" helps you find the objects in popup menu boxes.

If you attempt to use an object in your program without a Reference, the line of code generates an error.

The Imports statement, on the other hand, is never required, but it certainly makes things easier. The only thing it does is allow the name to be resolved without being fully qualified. In other words ...

~~~~~~~~~~~~~~~~~~~~~~~~~
Imports System.Data
Public Class Form1
  Inherits System.Windows.Forms.Form
  Private Sub Form1_Load( ...
    Dim Test As OleDb.OleDbCommand
  End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~

and

~~~~~~~~~~~~~~~~~~~~~~~~~
Imports System.Data.OleDb
Public Class Form1
  Inherits System.Windows.Forms.Form
  Private Sub Form1_Load( ...
    Dim Test As OleDbCommand
  End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~

... are both correct.

Explore Visual Basic

By Category

About.com Special Features

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Exploring Text Files and String Processing

©2009 About.com, a part of The New York Times Company.

All rights reserved.