title: Dynamically adding multiple rows in data table in C#
body: <p>I have been tried to use the DATATABLE for storing the values for the entire application. I haven't use any database for storing values permanently. This are the dummy values I could use through out the application.</p>
  
  <p><strong>The issue is actually whenever I add a new row value into my DATATABLE it just overrides the previous values in the DATATABLE instead of adding an new row.</strong></p>
  
  <p><em>Is there any chance to add multiple rows to the DATATABLE dynamically and I can use it through out the application session.</em></p>
  
  <p><strong>** MY REGISTER PAGE**</strong></p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
      DataTable myDataTable;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          myDataTable = new DataTable();
          myDataTable.Columns.Add("username");
          myDataTable.Columns.Add("firstname");
          myDataTable.Columns.Add("lastname");
          myDataTable.Columns.Add("password");
          myDataTable.Columns.Add("conpassword");
          myDataTable.Columns.Add("email");
  
          myDataTable.Rows.Add("kavi1", "kavi", "rajan", "123456", "123456", "kavi@gmail.com");
          myDataTable.Rows.Add("sri1", "sri", "prem", "123456", "123456", "sri@gmail.com");
          myDataTable.Rows.Add("mani1", "mani", "vanan", "123456", "123456", "mani@gmail.com");
          HttpContext.Current.Session["name"] = myDataTable;
  
          if (!IsPostBack)
          {
  
  
              if (Session["name"] != null)
              {
  
                  myDataTable = Session["name"] as DataTable;
  
              }
          }
  
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
  
          myDataTable.Rows.Add(new object []{ TextBox1.Text ,TextBox2.Text,TextBox3.Text , TextBox4.Text,TextBox5.Text ,TextBox6.Text });
          HttpContext.Current.Session["name"] = myDataTable;
  
          if (Session["name"] != null)
          {
              Response.Write("success");
  
          }
  
      }
  </code></pre>
  
  <p><strong>MY LOGIN PAGE</strong></p>
  
  <pre><code>public partial class login : System.Web.UI.Page
  {
      DataTable dtResult;
  
      protected void Page_Load(object sender, EventArgs e)
      {
          dtResult = (DataTable)Session["name"];
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
  
  
          for (int i = 0; i &lt; dtResult.Rows.Count; i++)
          {
  
              string un = dtResult.Rows[i].Field&lt;string&gt;("username");
              string fn = dtResult.Rows[i].Field&lt;string&gt;("password");
  
  
              if (TextBox1.Text == un &amp;&amp; TextBox2.Text == fn)
              {
                  //Response.Write("success");
                  Response.Redirect("home.aspx");
              }
  
          }
  
  
      }
  </code></pre>