Home > DeveloperSection > Forums > How to use Dataset in asp.net
Ankit Singh

Total Post:341

Posted on    January-12-2016 9:34 PM

 C# C#  ADO.Net 

 1 Reply(s)
 449  View(s)
Rate this:
I want to use detaset in asp.net.how to use this.

aditya kumar Patel

Total Post:254

Posted on    January-12-2016 9:44 PM

DataSet is a ado.net components.it is a collection of DataTables. you can use the DataSet type to store many DataTables in a single collection.

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

namespace Forumasp


public partial class DataSetDemo : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


if (!IsPostBack)


DataSet ds = CreateDataSet();

GridView1.DataSource = ds.Tables["Customer"];




private DataSet CreateDataSet()


DataSet dataset = new DataSet();

DataTable Customer = CreateStudentTable();


return dataset;


private DataTable CreateStudentTable()


DataTable Customer = new DataTable("Customer");

AddNewColumn(Customer, "System.Int32", "CustomerID");

AddNewColumn(Customer, "System.String", "CustomerName");

AddNewColumn(Customer, "System.String", "CustomerEmailid");

AddNewRow(Customer, 1, "Surendra", "surendra@yahoo.com");

AddNewRow(Customer, 2, "Mahesh Sharma", "mahesh@gmail.com");

AddNewRow(Customer, 3, "Mayank Singh", "mayank@gmail.com");

AddNewRow(Customer, 4, "Sohel", "sohel@gmail.com");

AddNewRow(Customer,5, "Vikram", "vikram@gmail.com");

return Customer;


private void AddNewColumn(DataTable table, string columnType, string columnName)


DataColumn column = table.Columns.Add(columnName, Type.GetType(columnType));


private void AddNewRow(DataTable table, int id, string name, string city)


DataRow newrow = table.NewRow();

newrow["CustomerID"] = id;

newrow["CustomerName"] = name;

newrow["CustomerEmailid"] = city;






<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataSet.aspx.cs" Inherits="Forumasp.DataSetDemo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">




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


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >


<asp:TemplateField HeaderText="CustomerID">

<ItemTemplate ><%#Eval("CustomerID") %></ItemTemplate>


<asp:TemplateField HeaderText="CustomerName">

<ItemTemplate ><%#Eval("CustomerName") %></ItemTemplate>


<asp:TemplateField HeaderText="E-mailaddress">

<ItemTemplate ><%#Eval("CustomerEmailid") %></ItemTemplate>









Modified On Jan-25-2016 06:21:57 AM

Don't want to miss updates? Please click the below button!

Follow MindStick