title: if/else statement for insert command parameters after select command is implemented c#?
body: <p>Access 2003
  VS 2010 C#</p>
  
  <p>Please can someone help me how to do a else statement. I have used if statement to check if duplicate record exist and I and struggling on how to use else statement when insert command parameters are used. Thanks in advance</p>
  
  <p>Here is the method for </p>
  
  <pre><code>  OleDbCommand cmd = new OleDbCommand();
          cmd.CommandType = CommandType.Text;
  
          using (var command = myCon.CreateCommand())
              {
                  command.CommandText = "select * from SomeTable where ID = @ID";
                  command.Parameters.AddWithValue("ID", int.Parse(txtID.Text));
  
                  myCon.Open();
                  var reader = command.ExecuteReader();
                  {
                      if (reader.HasRows)
                      {
                          while (reader.Read())
                          {
                              txtID.Text = reader["ID"].ToString();
  
                          }
                      } MessageBox.Show("ID Already exist");
                      else (reader.HasRows !=null // need here pls. 
                      {
  
                        cmd.CommandText = "INSERT INTO SomeTable (ID, AgeGroup, Gender) VALUES (@ID, @AgeGroup, @Gender)";
                        cmd.Parameters.AddWithValue("@ID", txtID.Text);
                        cmd.Parameters.AddWithValue("@AgeGroup", cBAgeGroup.Text);
                        cmd.Parameters.AddWithValue("@Gender", cBGender.Text);
                        cmd.Connection = myCon;
                        cmd.ExecuteNonQuery();
                      }
                   }
  
                  }
                    //  cmd.Connection = myCon;
                    //  cmd.ExecuteNonQuery();
                      myCon.Close();
  </code></pre>
  
  <p><strong>Update 2</strong>
  I have moved the cmd connection and cmd.ExecuteNonQuery in the else statement. I am able to check if id already exists and able to insert new record. So the code is executing as it should be. </p>
  
  <p>Thank you all for your advise. </p>