Visual Basic.NET
  Home arrow Visual Basic.NET arrow Using Data Sources with the DataGridView C...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

Using Data Sources with the DataGridView Control
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2006-11-09

    Table of Contents:
  • Using Data Sources with the DataGridView Control
  • How to generate a DataGridView control from a data source
  • How to edit the properties of a DataGridView control
  • How to edit the columns of a DataGridView control
  • A Product Maintenance application that uses a DataGridView control

  • 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
     
     
    ADVERTISEMENT


    Using Data Sources with the DataGridView Control


    (Page 1 of 5 )

    Last week, we began our discussion of using data sources with databases in Visual Studio 2005. This week, we conclude the tutorial. This article, the second of two parts, is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383).

    The schema file created by the Data Source Configuration Wizard

    After you complete the Data Source Configuration Wizard, the new data source is displayed in the Data Sources window you saw in figure 14-1. In addition to this data source, Visual Studio generates a file that contains the schema for the DataSet class. This file defines the structure of the dataset, including the tables it contains, the columns that are included in each table, the data types of each column, and the constraints that are defined for each table. It is listed in the Solution Explorer window and is given the same name you specified for the dataset in the last step of the Data Source Configuration Wizard with a file extension of xsd. In figure 14-5, for example, you can see the schema file named MMABooksDataSet.xsd. As you’ll learn later in this chapter, you can view a graphic representation of this schema by double-clicking on this file.

    Beneath the schema file, the Solution Explorer displays the file that contains the generated code for the DataSet class. In this figure, this code is stored in the MMABooksDataSet.Designer.vb file. When you create bound controls from the data source as shown in this chapter, the code in this class is used to define the DataSet object that the controls are bound to. Although you may want to view this code to see how it works, you shouldn’t change it. If you do, the dataset may not work correctly.

    By the way, you should know that a dataset that’s created from a dataset class like the one shown here is called a typed dataset. The code in the dataset class makes it possible for you to refer to the tables, rows, and columns in the typed dataset using the simplified syntax you’ll see in this chapter and the next chapter. In contrast, in chapter 16, you’ll learn how to create an untyped dataset. As you’ll see, you create this type of dataset using code.

    A project with a dataset defined by a data source

    Description

    1. After you create a data source, it’s displayed in the Data Sources window. Then, you can use it to create bound controls as shown in this chapter.
    2. Visual Studio also generates a file that contains the schema for the dataset defined by the data source. This file appears in the Solution Explorer and has a file extension of xsd. It defines the structure of the dataset, including the tables it contains, the columns in each table, the data types of each column, and the constraints for each table.
    3. Subordinate to the schema file is a file that contains the generated code for the dataset class. Visual Studio uses this class to create a dataset object when you add the data source to a form.

    Note

    • To see the files that are subordinate to the schema file, click the Show All Files button at the top of the Solution Explorer. Then, expand the node for the schema file.

    Figure 14-5.   The schema file created by the Data Source Configuration Wizard

    How to use a data source with a DataGridView control

    Once you’ve created a data source, you can use a DataGridView control to display a grid that can be used to add, update, or delete that data. The DataGridView control is new to .NET 2.0 and has been designed to work with data sources. Although this control provides much of the same functionality as the DataGrid control that was available with previous versions of .NET, it also contains some significant enhancements.

    More Visual Basic.NET Articles
    More By Murach Publishing


       · 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

    - Clocks and Countdowns
    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek