title: Checking if id and reg already exists
body: <p>I have this table Profile which has fields with user_Id and regNo and I want to check first if id and email are already exists before proceed to inserting data.</p>
  
  <p>In my code, I am able to validate only one row (either id or reg number), but if I am going to validate the two of them, it gives me an error, saying "Must declare the scalar variable @userid". I don't know if it is with my select that is wrong or something in my code.</p>
  
  <pre><code>SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
      con.Open();
      SqlCommand cmdd = new SqlCommand("select * from Profile where user_Id = @userid AND RegNo = @reg", con);
  
      SqlParameter param = new SqlParameter();
      //SqlParameter param1 = new SqlParameter();
      param.ParameterName = "@userid";
      param.ParameterName = "@reg";
  
      param.Value = txtid.Text;
      param.Value = txtregNo.Text;
  
      cmdd.Parameters.Add(param);
      //cmdd.Parameters.Add(param1);
  
  
      SqlDataReader reader = cmdd.ExecuteReader();
  
  
          if (reader.HasRows)
          {
              MessageBox("User Id/Registry Number already exists");
          }
  
  
          else
          {
              SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
              SqlCommand cmd = new SqlCommand("qry", con);
              cmd.CommandType = System.Data.CommandType.Text;
  
              cmd.Parameters.AddWithValue("@id", txtid.Text);
              cmd.Parameters.AddWithValue("@regno", txtregNo.Text);
              cmd.Parameters.AddWithValue("@name", txtname.Text);
  
              cmd.CommandType = System.Data.CommandType.StoredProcedure;
              con.Open();
              cmd.ExecuteNonQuery();
              MessageBox("successfully saved!");
  
          }
  </code></pre>
  
  <p>I am using C# with asp.net.</p>