How to store the value from radiobuttonlist to database in C# ASP.NET -


i need in storing values radiobuttonlist sql server 2008. code works fine when checked in database if values radiobuttonlist have been stored there's nothing in database.

asp.net

    <p>        hypertension<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">           <asp:listitem value="rbtrue">true</asp:listitem>        <asp:listitem selected="true" value="rbfalse">false</asp:listitem>       </asp:radiobuttonlist>    </p>  

in c#:

    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 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;             }           }       }  

if use

string selectedvalue2 = this.radiobuttonlist2.selectedvalue; 

you value of list button selected rbtrue or rbfalse

if want selected radiolistbuttons text use this

 string selectedvalue2 = this.radiobuttonlist1.selecteditem.text; 

try query

string sql = "insert tbtrcbase(hpn,hpntreatement,ish,ishtreatment,asthma,asthmatreatment,dm,dmtreatment,otherco,othercotreatment,secondhandsmoke,smoker,stopsmoking,occupation,cancerfamilyhistory,familywithcancer,parentwithcancer) values(@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17)"; 

hope helps


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -