title: Forgot Password in windows form c#
body: <p>In the code below: I want to warn a user when he/she tries to enter an email which is (is not) associated with the database. When I type something is not in my database, it says "Your record is not in our database". But when I enter a valid email it says: <strong>input string was not in a correct format</strong><br>
  so this line code doesnt work: <strong>smtpClient.Send(message);</strong></p>
  
  <pre><code>    string randomCode = "";
      public static string to;
      public ForgotPassword()
      {
          InitializeComponent();
      }
  
      private void btn_EmailSend_Click(object sender, EventArgs e)
      {
          string from, pass, messagebody;
          #region Generating random code
          Random ran = new Random();
          string randText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
          int Length_randText = randText.Length;
          for (int i = 0; i &lt; 5; i++)
          {
              randomCode += randText[ran.Next(Length_randText)];
          }
          #endregion
  
          MailMessage message = new MailMessage();
          to = txt_Email.Text;
          from = "------";
          pass = "------";
          messagebody = "You have requested to reset your password. Enter this \"" + randomCode + "\" - code to change your password";
          message.To.Add(to);
          message.From = new MailAddress(from);
          message.Body = messagebody;
          message.Subject = "Password resetting request";
          SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");
          smtpClient.EnableSsl = true;
          smtpClient.Port = 587;
          smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
          smtpClient.Credentials = new NetworkCredential(from, pass);
          try
          {
              using (DALC.GetConnection())
              {
                  SqlCommand cmd = new SqlCommand("select email from loginuser where email = '" + to + "'", DALC.con);
                  object result = cmd.ExecuteScalar();
                  if (Convert.ToInt16(result)&gt;0)
                  {
                      smtpClient.Send(message);
                      MessageBox.Show("I have sent your resetting code to you email. Check your inbox :)", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  }
                  else
                  {
                      MessageBox.Show("Your record is not in our database");
                  }
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
  
      }
  </code></pre>