This tutorial will show you how to create data table without SQL server in ASP.NET 2.0 and C#. This is very useful for storing temporary data.

Add a GridView control, two lable controls, three textbox controls and button control in the page

Insert data into datatable:

Add data to datatable which we have created:

protected void btnAdd_Click(object sender, EventArgs e)
{
if (txtUserName.Text.Trim() == “”)
{
this.lblTips.Text = “You must fill a username.”;
return;
}
else
{
AddDataToTable(this.txtUserName.Text.Trim(), this.txtFirstName.Text.Trim(), this.txtLastName.Text.Trim(), (DataTable)Session[“myDatatable”]);

this.GridView1.DataSource = ((DataTable)Session[“myDatatable”]).DefaultView;
this.GridView1.DataBind();

this.txtFirstName.Text = “”;
this.txtLastName.Text = “”;
this.txtUserName.Text = “”;
this.lblTips.Text = “”;
}
}
[/csharp]

Be noted “Session[“myDatatable”] = myDt;” is important to ensure we can add new data continually until the page be closed.

Download Source Files