Database
  Home arrow Database arrow Page 3 - ADO.NET 101: Data Rendering with a DataLis...
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? 
DATABASE

ADO.NET 101: Data Rendering with a DataList Control Introduction
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 10
    2005-11-29

    Table of Contents:
  • ADO.NET 101: Data Rendering with a DataList Control Introduction
  • Displaying Data from DataReader with a DataList Control
  • Data from a DataReader
  • Designing the ItemTemplate
  • Displayed data from DataReader

  • 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


    ADO.NET 101: Data Rendering with a DataList Control Introduction - Data from a DataReader


    (Page 3 of 5 )

    Getting a DataReader to read data from a table in a SQL 2000 Server database  will be considered. The details of reading the data were described in two earlier tutorials and hence will be summarized here.  The next picture shows the data link properties of the OleDB Connection. The provider used is the MS OleDB Provider for SQL Server. The Data Link Window is configured for connecting to the pubs database on the server.

     The SQLConnection1 on the web form will have the following for its connection string:

    workstation id=XPHTEK;packet size=4096;integrated security=SSPI;data source=XPHTEK; persist security info=False;initial catalog=pubs

    Now let's place a SqlCommand1 control on the web page. Set the connection string of this command to the one that was first added. For the CommandText the following query  was chosen.

    SELECT fname,  lname,  emp_id,  hire_date FROM employee ORDER BY
    lname

    Binding the DataList Control to data

    The DataList control is very similar to the DataGrid control. The DataList must be bound to the data source. Since we are using the DataReader as the data source, the DataList must be bound to the DataReader. The following code makes this possible.

    Private Sub Page_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    'Create a new SQL connection
    Dim conn As New SqlConnection
    conn = SqlConnection1
    'open connection
    conn.Open()
    'declare a Sql Command
    Dim cmd As SqlCommand
    cmd = SqlCommand1
    'declare a DataReader
    Dim dr As SqlDataReader
    dr = cmd.ExecuteReader
    DataList2.DataSource = dr
    'Bind data to control
    DataList2.DataBind()
    conn.close()
    End Sub
    

    More Database Articles
    More By Jayaram Krishnaswamy


       · In a series of articles I have tried to cover data rendering from an SQL Server...
     

    DATABASE ARTICLES

    - Building Applications with Anonymous Types
    - A Closer Look at Anonymous Types
    - Programming with Anonymous Types
    - Converting Your Excel Worksheet into a Worki...
    - Excel Reference
    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client





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