Database Code
  Home arrow Database Code arrow Page 3 - Using the AccessDataSource Control in VS 2...
Click Here
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 
VeriSign Whitepapers 
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? 
DATABASE CODE

Using the AccessDataSource Control in VS 2005
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2006-07-17

    Table of Contents:
  • Using the AccessDataSource Control in VS 2005
  • Querying the database
  • Binding the query result to a GridView
  • Binding data to a drop-down list 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
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Using the AccessDataSource Control in VS 2005 - Binding the query result to a GridView


    (Page 3 of 4 )

    GridView is an improvement over the DataGrid in many ways. This tutorial does not cover all the nice things about GridView, but simply uses it to display the result of running the query. At this point you may add a Command button and a GridView control to the default.aspx page as shown. If you click the little black arrow at the top left of the GridView Control (pointing backwards) you may get a hint as to the tasks you need to perform for this control. If you want you may choose the data source, in which case you need not write any code. Here, no source has been defined in the design mode. Only the Auto Format... hyperlink was clicked to make GridView look pretty.

    Binding data to a GridView Control

    To the click event of the button marked Select employees Information, type in  the following code.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As _

    System.EventArgs)
    Handles Button1.Click
    Dim ds As New AccessDataSource ds = AccessDataSource1 Response.Write(ds.CacheDuration & "<br>") Response.Write(ds.CacheExpirationPolicy & "<br>") Response.Write(ds.ConnectionString.ToString & "<br>") ds.DataFile = "~/App_Data/nwind.mdb" ds.DataSourceMode = SqlDataSourceMode.DataSet GridView1.DataSource = ds GridView1.DataBind() GridView1.Visible = True
    End Sub

    The code instantiates a new AccessDataSource control and assigns to it the configured control described earlier. The three statements write the CacheDuration, CacheDurationPolicy and the ConnectionString to the screen. These are not necessary for data binding, but written out of curiosity. However, the DataFile and DataSourceMode are necessary for the display. The binding of DataSource to GridView uses just one line of code. When you build the application and choose to display the default.aspx page by clicking on the Show employees Information button, you will see the following.

    More Database Code Articles
    More By Jayaram Krishnaswamy


       · It's not only athletes take steroids, even programs can. AccessDataSource control...
     

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...

    Iron Speed




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