Open Visual Basic 2008 Express, and create a new project.
Choose a Console Application, and name it whatever you want—I've named mine
ProductstoXml.
Figure 1
Our project will open with Module1.vb. In order to retrieve
data from our database, we need to add a LINQ to SQL class, which will provide
us with the methods for easy data access. Right-click on the project, choose
Add >> New Item. Select LINQ to SQL Classes, name it Products.dbml, and
click OK. We'll now have a split screen with the Object Relational Designer in
the left pane and a method creator on the right.
Figure 2
Click the Database Explorer link in the Object Relational
Designer. The Database Explorer toolbar should open. Add a Data Connection. Choose
Microsoft SQL Server Database File and click OK.
Figure 3
On the next screen, we need to Browse to the database, which
for SQL Server Express 2005 is installed by default at C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data. Choose Adventureworks_Data.mdf,
and click Open, then OK.
Figure 4
The connection to Adventureworks_Data.mdf will now be listed
in the Database Explorer toolbar. Expand the database, and then the Views. To
finish creating the class, locate the vProductModelCatalogDescription view and
drag and drop it onto the Object Relational Designer, as shown. If you're
prompted to copy the data file to your project, click No. Save this file, and
switch back to Module1.vb.
Figure 5