What is the Dataset in ASP.NET

Share it Please

Introduction: -

Here I will explain what is Dataset and uses of Dataset with example in asp.net using C# .

Description:-

In previous posts I explained What is Cloud Computing , Difference between .NET Framework 4.5 and .NET Framework 4.0, Basics of ASP.NET. Now I will explain what is Dataset and uses of Dataset with example in asp.net using c# .

What Is Dataset?
A dataset (or data set) is a collection of data.
Most commonly a dataset corresponds to the contents of a single database table, or a single statistical data matrix, where each column of the table represents a particular variable, and each row corresponds to a given member of the dataset in question. The dataset lists values for each of the variables, such as height and weight of an object, for each member of the dataset. Each value is known as a datum. The dataset may comprise data for one or more members, corresponding to the number of rows.

The term dataset may also be used more loosely, to refer to the data in a collection of closely related tables, corresponding to a particular experiment or event.


C# Specifications for code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using Arahan;

public partial class testing : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    DataFill d = new DataFill();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.fillgrd();
    }
    public void fillgrd()
    {
        DataSet dst = new DataSet();
        DataTable dt = new DataTable("People");
        dt.Columns.Add("id");
        dt.Columns.Add("name");
        dt.Columns.Add("Age");
        dt.Rows.Add("1","Amit Singh","21");
        dt.Rows.Add("2","Amitendra","21");
        dst.Tables.Add(dt);
        DataTable ds = new DataTable("new People");
        ds.Columns.Add("id");
        ds.Columns.Add("name");
        ds.Columns.Add("Age");
        ds.Rows.Add("1", "Amitendra", "21");
        ds.Rows.Add("2", "Amit Singh", "21");

        dst.Tables.Add(ds);

        dst.Tables["people"].Rows[0][0].ToString();
        dst.Tables["new People"].Rows[0][0].ToString();
        GridView1.DataSource = dst.Tables["new People"];
        GridView1.DataBind();
       
    }

}

ASPX Code Using Grid View:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testing.aspx.cs" Inherits="testing" %>

<!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></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td align="center"
                    style="font-family: verdana; font-size: medium; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #FFFFFF; background-color: #006699">
                    DataSet Entry</td>
            </tr>
            <tr>
                <td align="left"
                    style="font-family: verdana; font-size: small; font-weight: normal; font-style: normal; font-variant: normal; text-transform: none; color: #006699">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                        BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
                        CellPadding="3">
                        <FooterStyle BackColor="White" ForeColor="#000066" />
                        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                        <RowStyle ForeColor="#000066" />
                        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                        <SortedAscendingCellStyle BackColor="#F1F1F1" />
                        <SortedAscendingHeaderStyle BackColor="#007DBB" />
                        <SortedDescendingCellStyle BackColor="#CAC9C9" />
                        <SortedDescendingHeaderStyle BackColor="#00547E" />
                        <Columns>
                        <asp:TemplateField HeaderText="ID">
                        <ItemTemplate><asp:Label ID="lbl_id" runat="server" Text='<%#Eval("id") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>    
                        <asp:TemplateField HeaderText="Name">
                        <ItemTemplate>
                        <asp:Label ID="lbl_nme" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>  
                        <asp:TemplateField HeaderText="Age">
                        <ItemTemplate>
                        <asp:Label ID="lbl_age" runat="server" Text='<%#Eval("Age") %>'></asp:Label>
                        </ItemTemplate>
                        </asp:TemplateField>               
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
   
    </div>
    </form>
</body>

</html>


OUTPUT:



Subscribe via email

Enter your email address:

Delivered by FeedBurner

Blogroll