Retrieving Data from a SQL Server 2005 Database Using the SQL DataSource Control in ASP.NET 2.0
page 3 of 4
by Jayaram Krishnaswamy
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22920/ 23

Source Code

The following is the source code for the Default.aspx page and it includes all the modifications to the design applied to retrieve the result displayed in Figure 25.

Listing 1

<%@ Page Language="VB" AutoEventWireup="false" 
         CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<h3>Northwind Employees Data</h3>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" 
        runat="server" 
        AutoGenerateColumns="False"
        DataSourceID="SqlDataSource1" 
        EmptyDataText="There are no data records to display." 
        AllowPaging="True" 
        AllowSorting="True" 
        BackColor="White" 
        BorderColor="#DEDFDE" 
        BorderStyle="None" 
        BorderWidth="1px" 
        CellPadding="4" 
        ForeColor="Black" 
        GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" 
                              Font-Bold="True" 
                              ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" 
                        ForeColor="Black" 
                        HorizontalAlign="Right" />
            <HeaderStyle BackColor="#6B696B" 
                         Font-Bold="True" 
                         ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="EmployeeID" 
                               HeaderText="EmployeeID" 
                               InsertVisible="False"
                               ReadOnly="True" 
                               SortExpression="EmployeeID" />
                <asp:BoundField DataField="LastName" 
                                HeaderText="LastName" 
                                SortExpression="LastName" />
                <asp:BoundField DataField="FirstName" 
                                HeaderText="FirstName" 
                                SortExpression="FirstName" />
                <asp:BoundField DataField="City" 
                                HeaderText="City" 
                                SortExpression="City" />
                <asp:BoundField DataField="PostalCode" 
                                HeaderText="PostalCode" 
                                SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" 
                                HeaderText="Country" 
                                SortExpression="Country" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource 
            ID="SqlDataSource1" 
            runat="server" 
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
            ProviderName="<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>"
            SelectCommand="SELECT [EmployeeID], 
                                  [LastName], [FirstName], [City], 
                                  [PostalCode], [Country], [Photo], 
                                  [PhotoPath] FROM [Employees]">
        </asp:SqlDataSource>
    
    </div>           
    </form>
</body>
</html>

View Entire Article

User Comments

Title: sem   
Name: semtjo
Date: 2012-07-23 1:38:28 PM
Comment:
hai test server
Title: sdds   
Name: asdas
Date: 2012-05-29 8:52:13 AM
Comment:
asdasdas
Title: Retirve Data on Lost Focus in ASP.NET   
Name: jaypal
Date: 2011-12-02 11:16:15 PM
Comment:
I need to retrive data from SQLServer on lost focus of textbox or on Selected index change of Dropdownlist box...plz help
Title: Retirve Data on Lost Focus in ASP.NET   
Name: Shekhar Shete
Date: 2011-03-28 1:53:58 AM
Comment:
I need to retrive data from SQLServer on lost focus of textbox or on Selected index change of Dropdownlist box...plz help
Title: retrive data from sql server 2005 in c#code   
Name: Shwetha
Date: 2011-03-14 12:51:38 AM
Comment:
public void AddBrand()
{
DataServiceProvider dataServiceProvider = DataServiceProvider.Instance;
dataServiceProvider.GetData(..............)
}

this is my code.what do i need to write in...........space.
Title: Very Informative   
Name: Vamsee
Date: 2010-05-07 1:16:59 PM
Comment:
This is an excellent,informative article for Novices.
Title: hi   
Name: vani
Date: 2010-04-09 4:15:16 PM
Comment:
How can i get user details from SQL database to C#.net pages and store the in session varibles
Title: hi iam new 2 .net   
Name: vivek
Date: 2009-11-11 6:47:28 AM
Comment:
can u give me the guidence that how learn .net from basic
Title: how can i make manual drop down list connect to the DB   
Name: waleed
Date: 2009-05-17 2:53:54 AM
Comment:
I have a problem that i want to make send data by the drop down list to the table in data base but i can't do that

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 9:39:30 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search