How to Use Data Sources with Databases - How to start the Data Source Configuration Wizard
(Page 2 of 5 )
You can use the Data Source Configuration Wizard to create a data source for an application. Figure 14-2 shows the first step of this wizard. Since the steps of this wizard are mostly self-explanatory, this chapter only shows the ones that need some additional explanation. In particular, figure 14-3 shows how to create a new connection to a database, and figure 14-4 shows how to select the database objects that will be included in the dataset for the data source.
If your project doesn’t already contain a data source, you can start the Data Source Configuration Wizard by clicking the Add New Data Source link that’s in the Data Sources window. However, if your project already contains a data source, the Data Sources window will display a data source and this link won’t be available. In that case, you can start the Data Source Configuration Wizard by selecting the Add New Data Source command from the Data menu.
You can also start the Data Source Configuration Wizard by adding a SQL Server or Access database file to the project. You may want to do that if the application is for a single user. That way, the database can easily be distributed with the application as described in chapter 25.
If you add a database file to your project, you should know that by default, that file is copied to the output directory for the project every time the project is built. (The output directory is the directory where the executable file for the application is stored.) Then, when you run the application, the application works with the copy of the database file in the output directory. That means that any changes that you make to the database aren’t applied to the database file in the project directory. And each time you rebuild the application, the database in the output directory is overwritten by the unchanged database in the project directory so you’re back to the original version of the database.
If you want to change the way this works, you can select the database file in the Solution Explorer and change its “Copy to Output Directory” property from “Copy always” to “Copy if newer.” Then, the database file in the output directory won’t be overwritten unless the database file in the project directory contains more current data.
Next: How to choose a data source type >>
More Visual Basic.NET Articles
More By Murach Publishing
|
This article is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383). Check it out today at your favorite bookstore. Buy this book now.
|
|