title: c#.net Error: There is already an open DataReader associated with this Command which must be closed first
body: <p>Help, I am new to asp.net c#. I tried the codes once before but it didn't seems to have this error. So I can't seems to figure where do I make changes to.</p>
  
  <p>Sever error : 
  There is already an open DataReader associated with this Command which must be closed first. </p>
  
  <p>Codes:</p>
  
  <pre><code>string strConnectionString = ConfigurationManager.ConnectionStrings["FYPDB"].ConnectionString;
  
  SqlConnection myConnect = new SqlConnection(strConnectionString);
  
  string strCommandText = "select promoId FROM FYPDB.dbo.Promotions where membershipType LIKE '%' + @membership + '%' AND defaults LIKE '%' + @defaults + '%'";
  
  try
  {
      string ddlmembership = ((DropDownList)dvInsertPromotion.FindControl("ddlAddMembershiplist")).SelectedItem.ToString();
      string ddlDefault = ((RadioButtonList)dvInsertPromotion.FindControl("RadioButtonList2")).Text.ToString();
  
      DataSet da = dal.retrieveMembership(ddlmembership, ddlDefault);
      SiteGridView.DataSource = da;
      SiteGridView.DataBind();
  
  
      SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
  
      cmd.Parameters.Add("@membership", SqlDbType.NVarChar);
      cmd.Parameters.Add("@defaults", SqlDbType.NVarChar);
  
      cmd.Parameters["@membership"].Value = ddlmembership;
      cmd.Parameters["@defaults"].Value = ddlDefault;
  
      myConnect.Open();
      SqlDataReader reader = cmd.ExecuteReader();
  
  
      if (reader.Read())
      {
          //get number of count
          //int count = da.Tables[0].Rows.Count;
          int count = (int)cmd.ExecuteScalar();
  
          if (count == 1)
          {
              defaultComfirm.Show();
              promotion = false;
          }
  
      }
      else
      {
          Label6.Text = "error didnt go through";
          Label6.ForeColor = System.Drawing.Color.Gray;
          Label6.Visible = true;
      }
      reader.Close();
  }
  
  
  finally
  {
      myConnect.Close();
  }
  </code></pre>