Click here to Skip to main content
12,351,209 members (34,794 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 C# Windows , +
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 7-Dec-12 19:33pm
Code-Hunt7.1K
Edited 7-Dec-12 19:36pm
v2
Comments
Tadit Dash 8-Dec-12 1:35am
   
What language you are using for coding ?
Please tag that with your question.
Tadit Dash 8-Dec-12 1:43am
   
Can you show us any code, what you have tried so far ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi snehasis,

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

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.

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

insert into table name (column name) values ('" & checkbox1.checked & "')
  Permalink  
Comments
snehasish nandy 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100