Hi zulkarnain,
There is no need to change the table schema. You can save with comma separated in the column if user selects both the checkboxes.
Like Trainer, speaker.
Refer the below sample.
HTML
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server" />
</td>
</tr>
<tr>
<td>
Designation
</td>
<td>
<asp:CheckBox ID="cbTrainer" Text="Trainer" runat="server" />
<asp:CheckBox ID="cbSpeaker" Text="Speaker" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button Text="Save" runat="server" OnClick="Save" />
</td>
</tr>
</table>
C#
protected void Save(object sender, EventArgs e)
{
string name = txtName.Text.Trim();
List<string> designations = new List<string>();
if (cbTrainer.Checked) { designations.Add(cbTrainer.Text); }
if (cbSpeaker.Checked) { designations.Add(cbSpeaker.Text); }
string profile = string.Join(", ", designations);
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "INSERT INTO tblRegistration VALUES (@Name, @Profile)";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Profile", profile);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
VB.Net
Protected Sub Save(sender As Object, e As EventArgs)
Dim name As String = txtName.Text.Trim()
Dim designations As New List(Of String)()
If cbTrainer.Checked Then
designations.Add(cbTrainer.Text)
End If
If cbSpeaker.Checked Then
designations.Add(cbSpeaker.Text)
End If
Dim profile As String = String.Join(", ", designations)
Dim constr As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Using con As New SqlConnection(constr)
Dim query As String = "INSERT INTO tblRegistration VALUES (@Name, @Profile)"
Using cmd As New SqlCommand(query)
cmd.Connection = con
cmd.Parameters.AddWithValue("@Name", name)
cmd.Parameters.AddWithValue("@Profile", profile)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
End Using
End Sub
Output
If you select both Trainer, speaker then value inserted in database as Trainer, Speaker.
If you select Trainer then value inserted in database as Trainer.
If you select speaker then value inserted in database as Speaker.
If you didn't select any then value inserted in database as empty string.