2 Replies - 5135 Views - Last Post: 20 August 2011 - 07:00 AM Rate Topic: -----

#1 She'ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-August 11

how to insert multiple checkbox values in one column of mysql

Posted 20 August 2011 - 01:21 AM

How to insert multiple checkbox values(from c#) into one column of the database(mysql)?.


Suppose if a checkbox contain 4 values, if i choose 3 values,then how to insert that 3 values into the single table
Is This A Good Question/Topic? 0
  • +

Replies To: how to insert multiple checkbox values in one column of mysql

#2 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: how to insert multiple checkbox values in one column of mysql

Posted 20 August 2011 - 03:58 AM

View PostShe, on 20 August 2011 - 01:51 PM, said:

How to insert multiple checkbox values(from c#) into one column of the database(mysql)?.


Suppose if a checkbox contain 4 values, if i choose 3 values,then how to insert that 3 values into the single table

Hi,
You can store all Check values into string variable and pass this string to your table field(column)
private void button1_Click(object sender, EventArgs e)
            {
            string sTemp = CheckItemValues(this.panel1);
            string sSQL="INSERT INTO table(Field) Values('"+sTemp + "')";
           //
           //rest of your code
           //
            }

        public string CheckItemValues(Control parent)
            {
            string sString = null;

            foreach (Control ctl in parent.Controls)
                {
                if (ctl.Controls.Count > 0) CheckItemValues(ctl);
                if (ctl is CheckBox)
                    {
                    CheckBox chk = (CheckBox)ctl;
                    if (chk.Checked == true)
                        {
                        sString += chk.Text + ",";
                        }
                    }
                }
            return sString;
            }


Was This Post Helpful? 0
  • +
  • -

#3 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: how to insert multiple checkbox values in one column of mysql

Posted 20 August 2011 - 07:00 AM

Don't build strings with strings! Use StringBuilder!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1