Hi KatieNgoc,
Refer below sample.
HTML
<asp:CheckBox ID="CheckBox1" runat="server" Text="Jobtitle1" />
<br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="Jobtitle2" />
<br />
<asp:CheckBox ID="CheckBox4" runat="server" Text="Jobtitle3" />
<br />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Jobtitle4" />
<br />
<asp:CheckBox ID="CheckBox5" runat="server" Text="Jobtitle5" />
<br />
<asp:Button Text="Insert" runat="server" OnClick="Save" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data
Code
C#
protected void Save(object sender, EventArgs e)
{
SqlConnection con = null;
SqlCommand cmd = null;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
con = new SqlConnection(constr);
cmd = new SqlCommand("INSERT INTO jobTitle(Jobtitle1,Jobtitle2,Jobtitle3,Jobtitle4,Jobtitle5) VALUES(@Jobtitle1,@Jobtitle2,@Jobtitle3,@Jobtitle4,@Jobtitle5)", con);
cmd.Parameters.AddWithValue("@Jobtitle1", CheckBox1.Checked ? CheckBox1.Text : " ");
cmd.Parameters.AddWithValue("@Jobtitle2", CheckBox2.Checked ? CheckBox2.Text : " ");
cmd.Parameters.AddWithValue("@Jobtitle3", CheckBox3.Checked ? CheckBox3.Text : " ");
cmd.Parameters.AddWithValue("@Jobtitle4", CheckBox4.Checked ? CheckBox4.Text : " ");
cmd.Parameters.AddWithValue("@Jobtitle5", CheckBox5.Checked ? CheckBox5.Text : " ");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
VB.Net
Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
Dim con As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
con = New SqlConnection(constr)
cmd = New SqlCommand("INSERT INTO jobTitle(Jobtitle1,Jobtitle2,Jobtitle3,Jobtitle4,Jobtitle5) VALUES(@Jobtitle1,@Jobtitle2,@Jobtitle3,@Jobtitle4,@Jobtitle5)", con)
cmd.Parameters.AddWithValue("@Jobtitle1", If(CheckBox1.Checked, CheckBox1.Text, " "))
cmd.Parameters.AddWithValue("@Jobtitle2", If(CheckBox2.Checked, CheckBox2.Text, " "))
cmd.Parameters.AddWithValue("@Jobtitle3", If(CheckBox3.Checked, CheckBox3.Text, " "))
cmd.Parameters.AddWithValue("@Jobtitle4", If(CheckBox4.Checked, CheckBox4.Text, " "))
cmd.Parameters.AddWithValue("@Jobtitle5", If(CheckBox5.Checked, CheckBox5.Text, " "))
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub