Note that there are some explanatory texts on larger screens.

plurals
  1. POProper way of storing RadioButton values in DB
    primarykey
    data
    text
    <p>I need some suggestions on following code:</p> <p><strong>Scenario:</strong> Its like a Opinion poll, You have to choose Yes/No and the data will be stored on DB.But I think this code can be optimized,can some body suggest proper way of doing this. </p> <pre><code>&lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:radiobuttonlist id="RadioButtonList1" runat="server"&gt; &lt;asp:ListItem Text="yes" Value="1"&gt;&lt;/asp:ListItem&gt; &lt;asp:ListItem Text="No" Value="0"&gt;&lt;/asp:ListItem&gt; &lt;/asp:radiobuttonlist&gt; &lt;/div&gt; &lt;div&gt; &lt;asp:button id="Button1" runat="server" text="Submit" onclick="Button1_Click" /&gt; &lt;/div&gt; &lt;/form&gt; protected void Button1_Click(object sender, EventArgs e) { if (RadioButtonList1.Items.FindByValue("1").Selected == true) { string source = "Server=localhost;Database=Test;Trusted_Connection=yes"; SqlConnection con = new SqlConnection(source); con.Open(); SqlCommand cmd = new SqlCommand("proc_select", con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows==true) { while (dr.Read()) { int val = (int)dr["yes"]; val++; update(val); } } } if (RadioButtonList1.Items.FindByValue("0").Selected == true) { string source = "Server=localhost;Database=Test;Trusted_Connection=yes"; SqlConnection con = new SqlConnection(source); con.Open(); SqlCommand cmd = new SqlCommand("proc_select", con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows == true) { while (dr.Read()) { int val = (int)dr["No"]; val++; updateNo(val); } } } } public void update(int val) { string source = "Server=localhost;Database=Test;Trusted_Connection=yes"; SqlConnection con = new SqlConnection(source); SqlCommand cmdupd; con.Open(); cmdupd = new SqlCommand("proc_Update", con); cmdupd.Parameters.Add("@val", SqlDbType.NVarChar).Value = val; cmdupd.CommandType = CommandType.StoredProcedure; cmdupd.ExecuteNonQuery(); } </code></pre> <p><code>UpdateNo()</code> method will be same as <code>update()</code>.</p> <p>I will declare <code>sqlcommand</code> and source like things globally, so not on that area. Let me know if u want more information.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload