ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Insert multiple selected CheckBox text in Database using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="KatieNgoc"> KatieNgoc</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:CheckBox ID=&#34;CheckBox1&#34; runat=&#34;server&#34; Text=&#34;Jobtitle1&#34; /&gt; &lt;br /&gt; &lt;asp:CheckBox ID=&#34;CheckBox2&#34; runat=&#34;server&#34; Text=&#34;Jobtitle2&#34; /&gt; &lt;br /&gt; &lt;asp:CheckBox ID=&#34;CheckBox4&#34; runat=&#34;server&#34; Text=&#34;Jobtitle3&#34; /&gt; &lt;br /&gt; &lt;asp:CheckBox ID=&#34;CheckBox3&#34; runat=&#34;server&#34; Text=&#34;Jobtitle4&#34; /&gt; &lt;br /&gt; &lt;asp:CheckBox ID=&#34;CheckBox5&#34; runat=&#34;server&#34; Text=&#34;Jobtitle5&#34; /&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Insert&#34; runat=&#34;server&#34; OnClick=&#34;Save&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data.SqlClient; using System.Data; </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Configuration Imports System.Data.SqlClient Imports System.Data </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Save(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; SqlConnection con = null; &nbsp;&nbsp;&nbsp; SqlCommand cmd = null; &nbsp;&nbsp;&nbsp; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; &nbsp;&nbsp;&nbsp; con = new SqlConnection(constr); &nbsp;&nbsp;&nbsp; cmd = new SqlCommand("INSERT INTO jobTitle(Jobtitle1,Jobtitle2,Jobtitle3,Jobtitle4,Jobtitle5) VALUES(@Jobtitle1,@Jobtitle2,@Jobtitle3,@Jobtitle4,@Jobtitle5)", con); &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle1", CheckBox1.Checked ? CheckBox1.Text : " "); &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle2", CheckBox2.Checked ? CheckBox2.Text : " "); &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle3", CheckBox3.Checked ? CheckBox3.Text : " "); &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle4", CheckBox4.Checked ? CheckBox4.Text : " "); &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle5", CheckBox5.Checked ? CheckBox5.Text : " "); &nbsp;&nbsp;&nbsp; con.Open(); &nbsp;&nbsp;&nbsp; cmd.ExecuteNonQuery(); &nbsp;&nbsp;&nbsp; con.Close();&nbsp;&nbsp; }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs) &nbsp;&nbsp;&nbsp; Dim con As SqlConnection = Nothing &nbsp;&nbsp;&nbsp; Dim cmd As SqlCommand = Nothing &nbsp;&nbsp;&nbsp; Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString &nbsp;&nbsp;&nbsp; con = New SqlConnection(constr) &nbsp;&nbsp;&nbsp; cmd = New SqlCommand("INSERT INTO jobTitle(Jobtitle1,Jobtitle2,Jobtitle3,Jobtitle4,Jobtitle5) VALUES(@Jobtitle1,@Jobtitle2,@Jobtitle3,@Jobtitle4,@Jobtitle5)", con) &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle1", If(CheckBox1.Checked, CheckBox1.Text, " ")) &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle2", If(CheckBox2.Checked, CheckBox2.Text, " ")) &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle3", If(CheckBox3.Checked, CheckBox3.Text, " ")) &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle4", If(CheckBox4.Checked, CheckBox4.Text, " ")) &nbsp;&nbsp;&nbsp; cmd.Parameters.AddWithValue("@Jobtitle5", If(CheckBox5.Checked, CheckBox5.Text, " ")) &nbsp;&nbsp;&nbsp; con.Open() &nbsp;&nbsp;&nbsp; cmd.ExecuteNonQuery() &nbsp;&nbsp;&nbsp; con.Close()&nbsp;&nbsp; End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/101414/Insert-multiple-selected-CheckBox-text-in-Database-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/101414/Insert-multiple-selected-CheckBox-text-in-Database-using-C-and-VBNet-in-ASPNet/Wed, 24 Jul 2019 03:00:51 GMT