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
2 Replies - 3368 Views - Last Post: 20 August 2011 - 07:00 AM
#1
how to insert multiple checkbox values in one column of mysql
Posted 20 August 2011 - 01:21 AM
Replies To: how to insert multiple checkbox values in one column of mysql
#2
Re: how to insert multiple checkbox values in one column of mysql
Posted 20 August 2011 - 03:58 AM
She, 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
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;
}
#3
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!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|