Link to home
Start Free TrialLog in
Avatar of Sukesh Shukla
Sukesh Shukla

asked on

How to Fetch Data From Database into a gridview

I want to fetch the data from database into a gridview fulfilling certain conditions.....But the data is not getting displayed
Fdate.aspx.cs
ShowP1.aspx.cs
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Could you share the code of ShowP1.aspx as well? I suspect the GridView initialization part. BTW, did you debug the application to see the reader object has the expected values? If not, please debug and confirm the values are returned by the select command.
Avatar of Sukesh Shukla
Sukesh Shukla

ASKER

code of ShowP1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowP1.aspx.cs" Inherits="housing1.ShowP1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
            <Columns>
                <asp:BoundField DataField="Flat" HeaderText="Flat" SortExpression="Flat" />
                <asp:BoundField DataField="First_Name" HeaderText="First_Name" SortExpression="First_Name" />
                <asp:BoundField DataField="Middle_Name" HeaderText="Middle_Name" SortExpression="Middle_Name" />
                <asp:BoundField DataField="Last_Name" HeaderText="Last_Name" SortExpression="Last_Name" />
                <asp:BoundField DataField="Mobile_NO" HeaderText="Mobile_NO" SortExpression="Mobile_NO" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
                <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
                <asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
                <asp:BoundField DataField="Office_Add" HeaderText="Office_Add" SortExpression="Office_Add" />
                <asp:BoundField DataField="Native_Add" HeaderText="Native_Add" SortExpression="Native_Add" />
                <asp:BoundField DataField="PAN_Card" HeaderText="PAN_Card" SortExpression="PAN_Card" />
                <asp:BoundField DataField="Aadhar_Card" HeaderText="Aadhar_Card" SortExpression="Aadhar_Card" />
                <asp:BoundField DataField="Religion" HeaderText="Religion" SortExpression="Religion" />
                <asp:BoundField DataField="Business_Job" HeaderText="Business_Job" SortExpression="Business_Job" />
                <asp:BoundField DataField="Married_Unmarried" HeaderText="Married_Unmarried" SortExpression="Married_Unmarried" />
                <asp:BoundField DataField="No_Of_Members" HeaderText="No_Of_Members" SortExpression="No_Of_Members" />
                <asp:BoundField DataField="Joining_Date" HeaderText="Joining_Date" SortExpression="Joining_Date" />
                <asp:BoundField DataField="Leaving_Date" HeaderText="Leaving_Date" SortExpression="Leaving_Date" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HousingConnectionString %>" SelectCommand="SELECT * FROM [Ex_Primary_Member] ORDER BY [Flat]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

Since i'm a beginner , could you please help me with the steps of debugging too....
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShowP1.aspx.cs" Inherits="housing1.ShowP1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
            <Columns>
                <asp:BoundField DataField="Flat" HeaderText="Flat" SortExpression="Flat" />
                <asp:BoundField DataField="First_Name" HeaderText="First_Name" SortExpression="First_Name" />
                <asp:BoundField DataField="Middle_Name" HeaderText="Middle_Name" SortExpression="Middle_Name" />
                <asp:BoundField DataField="Last_Name" HeaderText="Last_Name" SortExpression="Last_Name" />
                <asp:BoundField DataField="Mobile_NO" HeaderText="Mobile_NO" SortExpression="Mobile_NO" />
                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
                <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
                <asp:BoundField DataField="Education" HeaderText="Education" SortExpression="Education" />
                <asp:BoundField DataField="Office_Add" HeaderText="Office_Add" SortExpression="Office_Add" />
                <asp:BoundField DataField="Native_Add" HeaderText="Native_Add" SortExpression="Native_Add" />
                <asp:BoundField DataField="PAN_Card" HeaderText="PAN_Card" SortExpression="PAN_Card" />
                <asp:BoundField DataField="Aadhar_Card" HeaderText="Aadhar_Card" SortExpression="Aadhar_Card" />
                <asp:BoundField DataField="Religion" HeaderText="Religion" SortExpression="Religion" />
                <asp:BoundField DataField="Business_Job" HeaderText="Business_Job" SortExpression="Business_Job" />
                <asp:BoundField DataField="Married_Unmarried" HeaderText="Married_Unmarried" SortExpression="Married_Unmarried" />
                <asp:BoundField DataField="No_Of_Members" HeaderText="No_Of_Members" SortExpression="No_Of_Members" />
                <asp:BoundField DataField="Joining_Date" HeaderText="Joining_Date" SortExpression="Joining_Date" />
                <asp:BoundField DataField="Leaving_Date" HeaderText="Leaving_Date" SortExpression="Leaving_Date" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FFF1D4" />
            <SortedAscendingHeaderStyle BackColor="#B95C30" />
            <SortedDescendingCellStyle BackColor="#F1E5CE" />
            <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HousingConnectionString %>" SelectCommand="SELECT * FROM [Ex_Primary_Member] ORDER BY [Flat]"></asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

Put the breakpoint in the ShowP1.aspx.cs at the GetResults() method. Run the application. The breakpoint would be hit. Press F10 each line. Once  reader = com.ExecuteReader(); is executed, see the value of reader in quick watch window. The table should data.

Please refer any guide/google on how to debug applications. You can get better idea.
Thank you...... Easwaran Paramasivam
ASKER CERTIFIED SOLUTION
Avatar of Easwaran Paramasivam
Easwaran Paramasivam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial