Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

I have 3 check box in my page along with other controls..
please tell me how to right the code to insert the value of check box selected by the user.

Thank you
Posted
Updated 7-Dec-12 19:36pm
v2
Comments
What language you are using for coding ?
Please tag that with your question.
Can you show us any code, what you have tried so far ?

Hi snehasis,

If you are using sql server then you can try the following code.

SQL
INSERT INTO (TableName) (Column Names) VALUES (@checkBox1, @checkBox2, @checkBox3)


Here @checkBox1, @checkBox2, @checkBox3 are the parameters to the insert statement.

For C# Code you can try the following code.

C#
foreach (DataListItem item in Security1.Items) {
        CheckBox CheckBox1 = (CheckBox)item.FindControl("CheckBox1");

        if (CheckBox1.Checked) {
            HiddenField h = (HiddenField)item.FindControl("FeaID");
            string add = "Insert into Carfeature (RecID,FeatureID) values ((select Max(RecID) from record),@FeatureID)";
            cmd[k] = new SqlCommand();
            cmd[k].CommandType = CommandType.Text;
            cmd[k].Parameters.Add("@FeatureID", SqlDbType.Int).Value = h.Value;
            cmd[k].CommandText = add;
            k++;
        }
}


For reference follow the following link. Insert Query

Thanks
 
Share this answer
 
insert into table name (column name) values ('" & checkbox1.checked & "')
 
Share this answer
 
Comments
[no name] 8-Dec-12 1:46am    
Please check the question..i told i have 3 check boxes..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900