title: object reference not set to an instance of an object asp.net,
body: <p>I have two problems:</p>
  
  <ol>
  <li>how can i use textbox in other way so it wont throw any error?</li>
  <li>i got an error :
  <br>
  
  <blockquote>
    <p>"object reference not set to an instance of an object.</p>
  </blockquote></li>
  </ol>
  
  <p>and i dont know how to fix it.
  please can someone take a look?</p>
  
  <pre><code>protected void DataGridView1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
  
          if (e.CommandName.Equals("InsertFooter"))
          {
  
  
              try
              {
  
                  System.Web.UI.WebControls.TextBox txtEmp_num = (System.Web.UI.WebControls.TextBox)DataGridView1.Controls[0].Controls[0].FindControl("txtEmp_num");
                  System.Web.UI.WebControls.TextBox txtEmp_fn = (System.Web.UI.WebControls.TextBox)DataGridView1.Controls[0].Controls[0].FindControl("txtEmp_fn");
                  System.Web.UI.WebControls.TextBox txtEmp_ln = (System.Web.UI.WebControls.TextBox)DataGridView1.Controls[0].Controls[0].FindControl("txtEmp_ln");
                  System.Web.UI.WebControls.TextBox txtEmp_phone = (System.Web.UI.WebControls.TextBox)DataGridView1.Controls[0].Controls[0].FindControl("txtEmp_phone");
                  System.Web.UI.WebControls.TextBox txtEmp_email = (System.Web.UI.WebControls.TextBox)DataGridView1.Controls[0].Controls[0].FindControl("txtEmp_email");
  
                  MySqlConnection conn = new MySqlConnection(connection);
                  MySqlCommand cmd = new MySqlCommand();
                  cmd.Connection = conn;
                  cmd.CommandText = "insert into employees(Emp_number,First_name,Last_name,Phone_num,Email) values(@1,@2,@3,@4,@5)";
  
  
  
                  cmd.Parameters.AddWithValue("@1", txtEmp_num.Text);
                  cmd.Parameters.AddWithValue("@2", txtEmp_fn.Text);
                  cmd.Parameters.AddWithValue("@3", txtEmp_ln.Text);
                  cmd.Parameters.AddWithValue("@4", txtEmp_phone.Text);
                  cmd.Parameters.AddWithValue("@5", txtEmp_email.Text);
                  conn.Open();
                  cmd.ExecuteNonQuery();
  
                  conn.Close();
                  Bind();
  
  
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
          }
  
      }
  </code></pre>