Update Checkboxlist to database in asp.net C#
<p>I want to update multi checkboxlist value to the the database. I already databound my checkboxlist from other table which is the medicine table. Now i want to update my value to consultation table, but i can not </p>

<p>`</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
     try
    {
       for (int i = 0; i &lt; txtcheckbox.Items.Count - 1; i++)
        {
          if (txtcheckbox.Items[i].Selected == true)
          {
                str = str + txtcheckbox.Items[i].Text + ",";
            }
         }


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        String sql = "UPDATE [consultation]  set mname3 = " + str + "  WHERE [conid] = @conid";

        con.Open();
        SqlCommand cmd = new SqlCommand(sql, con);

        cmd.Parameters.AddWithValue("@conid", txtconid);
        cmd.Parameters.AddWithValue("@mname3", str);

        int j = cmd.ExecuteNonQuery();
        if (j &gt; 0)
        {
            Label2.Visible = true;
            Label2.Text = "Successfully Complete Dispensary";

            txtconid.Text = "";
        }
        else
        {
            Label2.Visible = true;
            Label2.Text = "Not Successfully Complete Dispensary";

            txtconid.Text = "";
        }
             con.Close();
       }
        catch 
        {
          Label2.Visible = true;
           Label2.Text = "Error";

            txtconid.Text = "";
        }
}







    `
</code></pre>
