How to insert non repeted values when i click previous button in asp.net
<p>I have created online exam application (web based) in asp.net c#. In my application </p>

<ul>
<li><p>The first form contains a drop down list for
tests &amp; a start button.</p>

<p>When i select a particular test from the dropdownlist and then clicking the start button ,it goes to the next page. </p></li>
<li><p>this page contains one label for
question, radiobuttonlist for
answers, next &amp; previous button.</p></li>
</ul>

<p>In the first form :the click event of the start button, i have created non repeated random values (for question ids) i.e stored in array.
when it redirects to another page then 1st question from that array will display with answers &amp; after clicking next button next question will appear, here i have inserted selected values(answers selected in radiobuttonlist) by user in database to calculate score.<strong>The Problem is</strong>  when  clicking the previous button and then selecting another answer then it reinserts the record again as i want to update that value, not the repeated value. I have written the following code for this but it doesn't work. Here </p>

<pre><code>if (result != DBNull.Value)
</code></pre>

<p>this condition doesn't work correctly as i want to check that value exists or not.</p>

<p>Please help me?</p>

<pre><code> if (Convert.ToInt32(Session["Counter"]) &lt;= 7)
        {
            //a is the array of random values where Counter is my counter start value=1
            SqlCommand cmd = new SqlCommand("SELECT selected from Sel_Ans WHERE Quid=" + a[Convert.ToInt32(Session["Counter"]) - 1] + "", sqlconn);
            sqlconn.Open();
            var result = cmd.ExecuteScalar();
            if (result != DBNull.Value)
            {
                cmd = new SqlCommand("Update Sel_Ans Set Selected=@Selected WHERE Quid=" + a[Convert.ToInt32(Session["Counter"]) - 1] + "", sqlconn);
                SqlParameter Selected = cmd.Parameters.Add("@Selected", SqlDbType.Int, 50);

                Selected.Value = rb;
                sqlconn.Close();
                sqlconn.Open();
                cmd.ExecuteNonQuery();
                sqlconn.Close();

            }
            else
            {
                int t = Convert.ToInt32(Session["Counter"]);

                cmd = new SqlCommand("INSERT INTO Sel_Ans VALUES ('1', @Quid, @Selected, '1')", sqlconn);
                SqlParameter Quid = cmd.Parameters.Add("@Quid", SqlDbType.Int, 50);
                Quid.Value = a[t - 2];

                SqlParameter Selected = cmd.Parameters.Add("@Selected", SqlDbType.Int, 50);
                Selected.Value = rb;
                sqlconn.Close();
                sqlconn.Open();
                cmd.ExecuteNonQuery();
                sqlconn.Close();
            }
            sqlconn.Close();
        }
</code></pre>
