title: The variable name '@ID' has already been declared. Variable names must be unique within a query batch or stored procedure
body: <p>I have built a search function that will be searching by ID and by last name.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>SqlCommand cmd = new SqlCommand("SELECT [ID],[Name],[LastName],[FirstName],[FinalGrade] FROM DATABASE WHERE ID = @ID OR LastName = @lname");
  
  using (SqlConnection con = new SqlConnection(conString))
  {
      cmd.Connection = con;
      con.Open();
  
      cmd.Parameters.AddWithValue("@ID", ID);
      cmd.Parameters.AddWithValue("lname",lname);
  
      /*if (ID == null)
      {
          unitsParam.Value = DBNull.Value;
      }*/
  
      if(String.IsNullOrEmpty(ID))
      {
          cmd.Parameters.AddWithValue("@ID", DBNull.Value);
      }
  
      if (String.IsNullOrEmpty(lname))
      {
          cmd.Parameters.AddWithValue("@lname", DBNull.Value);
      }
  
      using (SqlDataReader sdr = cmd.ExecuteReader())
          if (sdr.HasRows)
          {
              while (sdr.Read())
              {
                  int i = 0;
  
                  // vm.SearchResults.Add(new ApqcrDirSearch
                  ApqcrDirModel aRec = new ApqcrDirModel();
  
                  aRec.ID = sdr.IsDBNull(i) ? null : sdr.GetString(i);
                  i++;
  
                  aRec.Name = sdr.IsDBNull(i) ? null : sdr.GetString(i);
                  i++;
  
                  aRec.LastName = sdr.IsDBNull(i) ? null : sdr.GetString(i);
                  i++;
  
                  aRec.FirstName = sdr.IsDBNull(i) ? null : sdr.GetString(i);
                  i++;
  
                  vm.SearchResults.Add(aRec);
              }
          }
  
          con.Close();
  }
  </code></pre>
  
  <p>How do I search by both ID and LastName ? Do I have to use <code>SqlCommandParameter</code>? If yes, how ?</p>