Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - How to Use Data Sources with Databases
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

How to Use Data Sources with Databases
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-11-02

    Table of Contents:
  • How to Use Data Sources with Databases
  • How to start the Data Source Configuration Wizard
  • How to choose a data source type
  • How to create a connection to a database
  • How to choose database objects for a data source

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    How to Use Data Sources with Databases - How to choose database objects for a data source


    (Page 5 of 5 )

    Figure 14-4 shows how you can use the last step of the Data Source Configuration Wizard to choose the database objects for a data source. This step lets you choose any tables, views, stored procedures, or functions that are available from the database. In some cases, you can just select the table you need from the list of tables that are available from the database. Then, all of the columns in the table are included in the dataset.

    If you want to include selected columns from a table, you can expand the node for the table and select just the columns you want. In this figure, for example, the node for the Products table has been expanded and the three columns that will be used by the Product Maintenance applications in this chapter are selected. Note that although these applications will allow data to be added to the Products table, the OnHandQuantity column can be omitted because it’s defined with a default value in the database. So when a new row is added to the database, the database will set this column to its default value.

    If you include a column with a default value in a dataset, you need to realize that this value isn’t assigned to the column in the dataset, even though the dataset enforces the constraints for that column. For instance, the OnHandQuantity column in the MMABooks database has a default value of zero and doesn’t allow nulls. But if you include this column in the dataset, its definition will have a default value of null and won’t allow nulls. As a result, an exception will be thrown whenever a new row is added to the dataset with a null value for the OnHandQuantity column.

    This means that either the user or the application must provide an acceptable value for the OnHandQuantity column. One way to do that is to provide a way for the user to enter a value for the column. Another way is to use the Dataset Designer to set the DefaultValue property for this column as described in this figure. You’ll learn more about working with the Dataset Designer later in this chapter.

    In a larger project, you might want to include several tables in the dataset. Then, the dataset will maintain the relationships between those tables whenever that’s appropriate. Or, you might want to use views, stored procedures, or functions to work with the data in the database. If you have experience working with views, stored procedures, and functions, you shouldn’t have any trouble understanding how this works. Otherwise, you can get another book such as Murach’s SQL for SQL Server to learn more about working with these types of objects.

    The last step of the Data Source Configuration Wizard

    Description

    1. In the last step of the Data Source Configuration Wizard, you can choose the database objects that you want to include in the dataset for your project.
    2. In this step, you can choose from any tables, views, stored procedures, or functions that are available from the database. In addition, you can expand the node for any table, view, stored procedure, or function and choose just the columns you want to include in the data source.
    3. You can also enter the name you want to use for the dataset in this dialog box. By default, the name is the name of the database appended with “DataSet”.

    How to work with columns that have default values

    • If a column in a database has a default value, that value isn’t included in the column definition in the dataset. Because of that, you may want to omit columns with default values from the dataset unless they’re needed by the application. Then, when a row is added to the table, the default value is taken from the database.
    • If you include a column that’s defined with a default value, you must provide a value for that column whenever a row is added to the dataset. One way to do that is to let the user enter a value. Another way is to display the Dataset Designer as described in figure 14-21, click on the column, and use the Properties window to set the DefaultValue property.

    Figure 14-4.   How to choose database objects for a data source

    Please check back next week for the conclusion of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Murach's Visual Basic 2005," published by...
     

    Buy this book now. 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.

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway