title: "ExecuteReader:Connection Property has not been initialized."
body: <pre><code>private void btnSave_Click(object sender, EventArgs e)
  {
      try
      {
          con = new SqlConnection("Data Source = LENOVO; Initial Catalog = MainData; Integrated Security = True");
          con.Open();
  
          string CheckID = "select StaffID from PersonsData where StaffID='" + txtStaffID.Text + "'";
          cm = new SqlCommand(CheckID);
  
          SqlDataReader rdr = null;
  
          rdr = cm.ExecuteReader();
  
          if (rdr.Read())
          {
              MessageBox.Show("Company Name Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
              txtStaffID.Text = "";
              txtStaffID.Focus();
          }
          else
          {
              byte[] img = null;
              FileStream fs = new FileStream(imgLoc, FileMode.Open, FileAccess.Read);
              BinaryReader br = new BinaryReader(fs);
              img = br.ReadBytes((int)fs.Length);
              string Query = "insert into PersonsData (StaffID, FullName, Email, Address, Picture) values('" + this.txtStaffID.Text + "','" + this.txtFullname.Text + "','" + this.txtEmail.Text + "','" + this.txtAddress.Text + "',@img)";
                      if (con.State != ConnectionState.Open)
                          con.Open();
                      cm = new SqlCommand(Query, con);
                      cm.Parameters.Add(new SqlParameter("@img", img));
                      int x = cm.ExecuteNonQuery();
                      con.Close();
                      MessageBox.Show(x.ToString() + "Successfully Saved!");
                  }
              }
  
              catch (Exception ex)
              {
                  con.Close();
                  MessageBox.Show(ex.Message);
              }
  
          }
  </code></pre>
  
  <p>This is my code i don't understand why I'm getting this error: </p>
  
  <blockquote>
    <p>ExecuteReader:Connection Property has not been initialized.</p>
  </blockquote>
  
  <p>I'm making a save button where the Staffid will be checked first if already.</p>