3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by __avd
0

With something like this:

DataRow newRow = dataSet1.Tables["Customers"].NewRow();

newRow["CustomerID"] = "ALFKI";
newRow["CompanyName"] = "Alfreds Futterkiste";

dataSet1.Tables["Customers"].Rows.Add(newRow);

You add a dataRow to the existing dataTable and then specify what data you want to put in the columns. If you don't have columns specified like the example above you need to create the actual columns too (really only useful if you are creating the dataTable from scratch). If you have populated the dataTable from any type of data source the columns should be named.

0

I think you are aware of ASP.NET page life cycle. The Page and all objects (controls and other) will be created each time whenever a page is requested. So you need to use the state management - session to persist the DataTable/DataSet instance.

In page_load handler

if(!IsPostBack)
{
   DataTable dt=new DataTable();
   dt.Columns.Add("No");
   dt.Columns.Add("Name");
   Session["dt"]=dt;
 }

And in Button's Click handler

DataTable dt=(DataTable)Sesstion["dt"];
dt.Rows.Add(TextBox1.Text,TextBox2.Text);

Edited by __avd: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.