ASP.NET
  Home arrow ASP.NET arrow Retrieving Data from Microsoft SQL Server ...
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? 
ASP.NET

Retrieving Data from Microsoft SQL Server 2008 Using ASP.NET 3.5
By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2010-03-03

    Table of Contents:
  • Retrieving Data from Microsoft SQL Server 2008 Using ASP.NET 3.5
  • Configuring SqlDataSource Controls
  • Displaying the Query Results using Data Web Controls
  • Tell GridView the 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
     
     
    ADVERTISEMENT


    Retrieving Data from Microsoft SQL Server 2008 Using ASP.NET 3.5


    (Page 1 of 4 )

    Most of the web applications on the Internet require retrieving data from a database. Almost all websites today are database-driven, so it is of primary importance for any developer to retrieve data from a website's database and display it on the web browser. This article illustrates basic ways of retrieving data from Microsoft SQL Server 2008 using the ASP.NET 3.5 web platform.

     Purposely, this article is written for first time developers in ASP.NET and MS SQL server 2008. However it is highly recommended to read the pre-requisite tutorial: "Creating an ASP.NET Database using MS SQL 2008 in Visual Web Developer 2008," because the database that you create in that article will be used in the exercises illustrated in this tutorial.

    As a review, the sample database table has four records, or rows, in the database, and six fields:

    If you are ready, then let's start the ball rolling.

    Introducing: ASP.NET Data Source Controls

    Most of the web development work in ASP.NET 3.5 is handled by so-called "web controls," a click-and-drag strategy implemented in Visual Web Developer Express 2008. For example, if you want to include a server-side text box form, simply click and drag Textbox in the toolbox to the Default.aspx source code.

    Web controls make web development faster and simpler (because of the simple click-and-drag method, with the source code automatically generated by Visual Web Developer). They also save the developer from needing to write sophisticated and complex ASP.NET scripts.

    To retrieve data from the MS SQL 2008 database, you need an ASP.NET 3.5 page and a working database (which is thoroughly discussed in the article linked to above). Once you have these preliminary requirements, though, there is still no way for ASP.NET to communicate, connect and retrieve records from the MS SQL database.

    In ASP.NET, a web control set called "Data Source" controls is designed to connect to and interact with the database. Currently there are two important Data Source controls in ASP.NET (which you can see in View à Toolbox à Data):  SqlDataSource and AccessDataSource.

    SqlDataSource is primarily used for retrieving records from SQL databases such as MS SQL Server 2008 (or other supported databases, like Oracle). AccessDataSource is used when retrieving records from MS Access database.

    In the previous example, since you are using an MS SQL Server 2008 database, you will be using SqlDataSource controls to retrieve data. The following are the steps you need to take:

    Step 1: Launch Visual Web Developer Express 2008.

    Step 2: Open "firstdatabasetest" projects (containing the database, default.aspx and other files created from the first tutorial, referred to earlier). 

    Step 3: You will then see the source code of Default.aspx. Go to View à Toolbox à SqlDataSource, click and drag "SqlDataSource" to between <form id="form1" runat="server"><div> and </div></form>

    After the click and drag, the source code will be updated automatically:

        <form id="form1" runat="server">

        <div>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

        </div>

        </form>

    More ASP.NET Articles
    More By Codex-M


     

    ASP.NET ARTICLES

    - ASP.NET 3.5: User Access Rules
    - ASP.NET 3.5: Creating Role Based Security wi...
    - ASP.NET 3.5 Role Based Security and User Aut...
    - Canonicalizing DotNetNuke URLs in ASP.NET 3.5
    - ASP.Net 3.5: User Account Creation for Your ...
    - ASP.NET 3.5 Basic User Account Management
    - Generate Dynamic Title Tag based on QueryStr...
    - Add a Blog Module in DotNetNuke
    - ASP.NET 3.5 Basic Navigation Controls
    - Create ASP.NET 3.5 Sitemap XML for Navigatio...
    - Completing Basic DotNetNuke Website Developm...
    - DotNetNuke Website Development in ASP.NET 3.5
    - ASP.NET Querystring: Basic Dynamic URL Forma...
    - InsertItemTemplate FormView Example in ASP.N...
    - Using the FormView Web Control in ASP.NET 3.5





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