title: Public Int showing 0 when being used in different Class
body: <p>I'm trying to set a public int using a button click from a class then using create a new instance and use the value in another class to then be inserted into a DB.</p>
  
  <p>I'm using webforms and C# to produce my system. Any help with this is much appreciated.</p>
  
  <p>CLASS 1 --------------------------------</p>
  
  <pre><code> public partial class Index : System.Web.UI.Page
      {
  
          public int ID1;
  
          public void bLogin_Click(object sender, EventArgs e)
          {
              string username = tbUsername.Text;
              string password = tbPassword.Text;
  
              SqlCommand cmd2 = new SqlCommand("select UsersID from [dbo].[Users] where Username=@uname and Password=@password");
              cmd2.Connection = con;
              cmd2.Parameters.AddWithValue("@uname", tbUsername.Text);
              cmd2.Parameters.AddWithValue("@password", tbPassword.Text);
  
              int Result2 = (int)cmd2.ExecuteScalar();
              ID1 = Result2;
  
              if (Result &gt; 0)
              {
                  MessageBox.Show("Welcome");
                  MessageBox.Show(ID1.ToString());
                  Response.Redirect("Dashboard.aspx");
                  con.Close();
  
              }
              else
              {
                  MessageBox.Show("Incorrect");
              }
  
          }
  
         }
  }
  </code></pre>
  
  <p>CLASS 2 -----------------------------------</p>
  
  <pre><code>protected void bSubmit_Click(object sender, EventArgs e)
          {
  
              SQLDatabase.DatabaseTable module_table = new SQLDatabase.DatabaseTable("Boards");   // Need to load the table we're going to insert into.
  
              SQLDatabase.DatabaseRow new_row = module_table.NewRow();    // Create a new based on the format of the rows in this table.
  
  
              Index index = new Index();
              string new_id = module_table.GetNextIDBoards().ToString();    // Use this to create a new ID number for this module. This new ID follows on from the last row's ID number.
              string title = tbTitle.Text;
              string body = tbContent.Text;
              DateTime now = DateTime.Now;
              string date = now.GetDateTimeFormats('d')[0];
              string time = now.GetDateTimeFormats('t')[0];
  
              new_row["BoardsID"] = new_id;                                 // Add some data to the row (using the columns names in the table).
              new_row["Title"] = title;
              new_row["Body"] = body;  // Module name.
              new_row["UsersID"] = index.ID1.ToString();
              new_row["DateCreated"] = date;
              new_row["TimeCreated"] = time;
  
              module_table.Insert(new_row);                           // Execute the insert - add this new row into the database.
  
              MessageBox.Show("New Board Created");
              Response.Redirect("Dashboard.aspx");
  
  
          }
  </code></pre>
  
  <p>You can see im trying to transfer the ID across classes.</p>
  
  <p>The database insert is fine but its inseting "0" for the ID.</p>