The parameterized query ... expects the parameter ... which was not supplied
<p>I was trying to create a simple data form with check boxes. Its like a duty request form with where check boxes represents each duty slot.</p>

<p>I'm testing it so the userID is simply selected from a dropdown list (ddlID). </p>

<p>Whenever the ddlID's selected index is changed, the duty data is pulled from the database and shown to the user with the form therefore user can request the available slot or release the slot if he/she have requested before. If someone has already requested a particular slot before, that particular checkbox will be disabled.</p>

<p>Below is the code behind of my page.</p>

<pre><code>string PCS1, R1S1 = "somevalue";
    protected void Page_Load(object sender, EventArgs e)
    {
        lblDate.Text = DateTime.Now.ToLongDateString();
    }
    protected void ddlID_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString);
            SqlCommand cmd = sqlConn.CreateCommand();

            cmd.CommandText = "SELECT * FROM tbl_duty_location WHERE Shift = 'S1'";

            sqlConn.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    if (reader["PC"].ToString() == "n")
                    {
                        PCS1 = "n";
                    }
                    else if (reader["PC"].ToString() != "n")
                    {
                        PCS1 = reader["PC"].ToString();
                    }

                    if (reader["R1"].ToString() == "n")
                    {
                        R1S1 = "n";
                    }
                    else if (reader["R1"].ToString() != "n")
                    {
                        R1S1 = reader["R1"].ToString();
                    }

                }
            }

            if (PCS1 == ddlID.SelectedItem.ToString())
            {
                chkPCS1.Enabled = true;
                chkPCS1.Checked = true;
            }
            else if (PCS1 == "n")
            {
                chkPCS1.Enabled = true;
                chkPCS1.Checked = false;
            }
            else if (PCS1 != ddlID.SelectedItem.ToString())
            {
                chkPCS1.Enabled = false;
                chkPCS1.Checked = false;
            }

            if (R1S1 == ddlID.SelectedItem.ToString())
            {
                chkR1S1.Enabled = true;
                chkR1S1.Checked = true;
            }
            else if (R1S1 == "n")
            {
                chkR1S1.Enabled = true;
                chkR1S1.Checked = false;
            }
            else if (R1S1 != ddlID.SelectedItem.ToString())
            {
                chkR1S1.Enabled = false;
                chkR1S1.Checked = false;
            }
            reader.Close();
            sqlConn.Close();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (chkPCS1.Enabled == false)
        {
            Trace.Write("PCS1 is: ", PCS1);
        }
        else if (chkPCS1.Checked == false)
        {
            PCS1 = "n";
        }
        else if (chkPCS1.Checked)
        {
            PCS1 = ddlID.SelectedItem.ToString();
        }

        if (chkR1S1.Enabled == false)
        {
            Trace.Write("R1S1: ", R1S1);
        }
        else if (chkR1S1.Checked == false)
        {
            R1S1 = "n";
        }
        else if (chkR1S1.Checked)
        {
            R1S1 = ddlID.SelectedItem.ToString();
        }

        SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString);
        SqlCommand cmd = sqlConn.CreateCommand();

        cmd.CommandText = "UPDATE tbl_duty_location SET PC = @PC1, R1 = @R1 WHERE Shift = '1'";
        cmd.Parameters.AddWithValue("PC1", PCS1);
        cmd.Parameters.AddWithValue("R1", R1S1);

        sqlConn.Open();
        cmd.ExecuteNonQuery();
        sqlConn.Close();
    }
</code></pre>

<p>Currently, in the table, column "PC" already has userID which means that particular slot is unavailable. </p>

<p>However, when I tried to request another slot using different userID, I got the follow error.</p>

<p><code>The parameterized query '(@PC1 nvarchar(4000),@R1 nvarchar(9))UPDATE tbl_duty_location SE' expects the parameter '@PC1', which was not supplied.</code></p>

<p>Actually, @PC1 is supposed to be PCS1 which is loaded from the database but PCS1 immediately become null once the btn_submit click event is occurred. </p>

<p>What could be the problem?</p>
