title: SQL commands not working in C# (ASP.NET web forms)
body: <p>I'm having a trouble with my code.
  I'm trying to have the user the ability to submit his email to subscribe to my &quot;notify me&quot; service, I havn't code anything lately so I a bit confused..</p>
  <p>I'm trying to Insert, Read, and Update data in my Online SQL Server.. but nothing seems to work! I don't know why I tried everything I know I check a million times it seems good.
  Plus if there is any errors my catch should show it to me but even that doesn't work :(</p>
  <p>Take a look at this maybe your eyes will see something I don't see.</p>
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
      {
          string cs = ConfigurationManager.ConnectionStrings[&quot;notifyCS&quot;].ConnectionString;
          using (SqlConnection conn = new SqlConnection(cs))
          {
              conn.Open();
              try
              {
                  string checkEmail = &quot;SELECT User_Email FROM tbl_users WHERE User_Email = @User_Email&quot;;
                  string checkSubscription = &quot;SELECT User_Status FROM tbl_users WHERE User_Email = @User_Email&quot;;
                  string submitEmail = &quot;INSERT INTO tbl_users (User_UID, User_Email, User_Status) VALUES (@User_UID, @User_Email, @User_Status)&quot;;
                  string submitEmail2 = &quot;UPDATE tbl_users SET User_UID = @User_UID, User_Status = @User_Status WHERE User_Email = @User_Email&quot;;
                  SqlCommand emailCMD = new SqlCommand(checkEmail, conn);
                  SqlDataAdapter emailSDA = new SqlDataAdapter
                  {
                      SelectCommand = emailCMD
                  };
                  DataSet emailDS = new DataSet();
                  emailSDA.Fill(emailDS);
                  //if there is no email registered.
                  if (emailDS.Tables[0].Rows.Count == 0)
                  {
                      SqlCommand registerEmail = new SqlCommand(submitEmail, conn);
                      string User_UID = System.Guid.NewGuid().ToString().Replace(&quot;-&quot;, &quot;&quot;).ToUpper();
                      registerEmail.Parameters.AddWithValue(&quot;@User_UID&quot;, HttpUtility.HtmlEncode(User_UID));
                      registerEmail.Parameters.AddWithValue(&quot;@User_Email&quot;, HttpUtility.HtmlEncode(email.Text));
                      registerEmail.Parameters.AddWithValue(&quot;@User_Status&quot;, HttpUtility.HtmlEncode(&quot;subscribed&quot;));
                      registerEmail.ExecuteNonQuery();
                      registerEmail.Dispose();
                      conn.Close();
                      conn.Dispose();
                      email.Text = null;
                  }
                  else if (emailDS.Tables[0].Rows.Count &gt; 0)
                  {
                      using (SqlCommand checkSub = new SqlCommand(checkSubscription, conn))
                      {
                          checkSub.Parameters.AddWithValue(&quot;@User_Email&quot;, HttpUtility.HtmlEncode(email.Text));
                          SqlDataReader sdr = checkSub.ExecuteReader();
                          if (sdr.HasRows)
                          {
                              string res = sdr[&quot;User_Status&quot;].ToString();
                              if (res != &quot;subscribed&quot;)
                              {
                                  using (SqlCommand registerEmail2 = new SqlCommand(submitEmail2, conn))
                                  {
                                      string User_UID = System.Guid.NewGuid().ToString().Replace(&quot;-&quot;, &quot;&quot;).ToUpper();
                                      registerEmail2.Parameters.AddWithValue(&quot;@User_UID&quot;, HttpUtility.HtmlEncode(User_UID));
                                      registerEmail2.Parameters.AddWithValue(&quot;@User_Email&quot;, HttpUtility.HtmlEncode(email.Text));
                                      registerEmail2.Parameters.AddWithValue(&quot;@User_Status&quot;, HttpUtility.HtmlEncode(&quot;subscribed&quot;));
                                      registerEmail2.ExecuteNonQuery();
                                      registerEmail2.Dispose();
                                      conn.Close();
                                      conn.Dispose();
                                      email.Text = null;
                                  }
                              }
                              else
                              {
                                  conn.Close();
                                  conn.Dispose();
                                  Response.Redirect(&quot;index.aspx&quot;);
                              }
                          }
                      }
                  }
              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message);
              }
              finally
              {
                  conn.Close();
                  if (conn.State != ConnectionState.Closed)
                  {
                      conn.Close();
                      conn.Dispose();
                  }
              }
          }
      }
  </code></pre>