title: How to store the value from radiobuttonlist to database in C# ASP.NET
body: <p>I need help in storing the values from the radiobuttonlist to SQL Server 2008. My code works fine but when I checked in the database if my values from the radiobuttonlist have been stored there's nothing in the database. </p>
  
  <p>asp.net </p>
  
  <pre><code>    &lt;p&gt;
         Hypertension&lt;asp:RadioButtonList 
          ID="RadioButtonList1" 
          RepeatColumns ="2" RepeatDirection = "vertical" 
          RepeatLayout= "table" runat="server" 
          AutoPostBack="True" 
           onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" 
           Width="250px" Height="10px" style="margin-left: 0px" BorderStyle="None" 
            CellPadding="1" CellSpacing="1"&gt;
            &lt;asp:ListItem Value="rbtrue"&gt;TRUE&lt;/asp:ListItem&gt;
         &lt;asp:ListItem Selected="True" Value="rbfalse"&gt;FALSE&lt;/asp:ListItem&gt;
        &lt;/asp:RadioButtonList&gt;
     &lt;/p&gt; 
  </code></pre>
  
  <p>In C#:</p>
  
  <pre><code>    protected void Button1_Click(object sender, EventArgs e)
      {
          //Response.Redirect("WebForm1.aspx");
          string selectedValue1 = this.RadioButtonList1.SelectedValue;
          string selectedValue2 = this.RadioButtonList2.SelectedValue;
  
          using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TumorRegistryConnectionString1"].ConnectionString))
          {
              string sql = "Insert into tbTRcBase(HPN,HPNTreatement,ISH,ISHTreatment,Asthma,AsthmaTreatment,DM,DMTreatment,OtherCo,OtherCoTreatment,SecondHandSmoke,Smoker,StopSmoking,Occupation,CancerFamilyHistory,FamilyWithCancer,ParentWithCancer) value(@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17)";
  
              SqlCommand cmd = new SqlCommand();
              cmd.Connection = conn;
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = sql;
              cmd.Parameters.AddWithValue("@d1", selectedValue1);
              cmd.Parameters.AddWithValue("@d2", selectedValue2);
  
              try
              {
                  if (conn.State != ConnectionState.Open)
                      conn.Open();
                  int result = cmd.ExecuteNonQuery();
              }
              catch (Exception ex)
              {
                  Response.Write(ex.Message);
                  return;
              }
            }
        } 
  </code></pre>