Create DataSet by your own : DataSet « ADO.net Database « ASP.NET Tutorial






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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="lstUser" runat="server" Height="152px" Width="192px"></asp:ListBox></div>
    </form>
</body>
</html>


File: Default.aspx.cs


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataSetBinding : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet dsInternal = new DataSet();
        dsInternal.Tables.Add("Users");

        dsInternal.Tables["Users"].Columns.Add("Name");
        dsInternal.Tables["Users"].Columns.Add("Country");

        DataRow rowNew = dsInternal.Tables["Users"].NewRow();
        rowNew["Name"] = "A";
        rowNew["Country"] = "USA";
        dsInternal.Tables["Users"].Rows.Add(rowNew);

        rowNew = dsInternal.Tables["Users"].NewRow();
        rowNew["Name"] = "B";
        rowNew["Country"] = "Canada";
        dsInternal.Tables["Users"].Rows.Add(rowNew);

        rowNew = dsInternal.Tables["Users"].NewRow();
        rowNew["Name"] = "C";
        rowNew["Country"] = "Japan";
        dsInternal.Tables["Users"].Rows.Add(rowNew);

        lstUser.DataSource = dsInternal.Tables["Users"];
        lstUser.DataTextField = "Name";

        lstUser.DataSource = dsInternal;
        lstUser.DataMember = "Users";
        lstUser.DataTextField = "Name";

        this.DataBind();

    }
}








18.27.DataSet
18.27.1.The DataSet object represents an in-memory database.
18.27.2.Fill a DataSet
18.27.3.Iterating Through A DataSet
18.27.4.Fill DataSet with SqlDataAdapter
18.27.5.Use OleDbDataAdapter to fill DataSet
18.27.6.Iterating Through A DataSet from MySQL database
18.27.7.List Binding To A DataSet
18.27.8.Pulling Single Values From Dataset Bounded Lists
18.27.9.Create DataSet by your own
18.27.10.Serialization capabilities of DataSet