title: How to check if I have the username in database C#?
body: <p>I'm new in C# and databases. I made a database in which I add data from a person. Actually, are data from a person who create an account. I checked if the email have email structure and I checked if password is the same with the retype password. Here you have the code: </p>
  
  <pre><code>if (Pass.Text != Rpass.Text)
          {
              MessageBox.Show("Password don't match!");
              return;
          }
          string emailCheck = Email.Text;
  
          bool valid = false;
          int count_dot = 0;
  
          for (int i = 0; i &lt; emailCheck.Length; i++)
              if (emailCheck[i] == '@') valid = true;
              else if (emailCheck[i] == '.') count_dot++;
  
          if (valid == false || count_dot == 0)
          {
              MessageBox.Show("Invalid email!");
              return;
          }
          con = new SqlConnection(@"Data Source=MARIA-PC;Initial Catalog=Account;Integrated Security=True");
          con.Open();
          cmd = new SqlCommand("INSERT into [dbo].[Cont1] (Username,Password,First_name,Last_name,Birth_year,Email,Work_type) VALUES (@Username,@Password,@First_name,@Last_name,@Birth_year,@Email,@Work_type)", con);
          cmd.Parameters.Add("@Username", Username.Text);
          cmd.Parameters.Add("@Password", Password.Text);
          cmd.Parameters.Add("@First_name", First_name.Text);
          cmd.Parameters.Add("@Last_name", Last_name.Text);
          cmd.Parameters.Add("@Birth_year", DateTime.Parse(Birth_year.Text));
          cmd.Parameters.Add("@Email", Email.Text);
          cmd.Parameters.Add("@Work_type", Work_tpye.SelectedItem.ToString());
          cmd.ExecuteNonQuery();
  
          con.Close();
  </code></pre>
  
  <p>So, what I want to do is to check, before to add in database, if I already have the Username in database. I have the idea what I have to do, but I don't know how to do. </p>