473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to insert a value in database using checkbox?

Here i'm using two checkboxes with yes or no format.. When i check yes it should store '1' in the database and when i check no it should store '0' in the database..
Attached Images
File Type: jpg isactive.JPG (6.8 KB, 629 views)
Aug 4 '10 #1
3 9302
Curtis Rutland
3,256 Expert 2GB
First of all, this would be much better suited to Radio Buttons, since they are mutually exclusive.

But you would use .Checked in either case to get true or false. Then you just do your normal insert into a database. The "bit" datatype is the best for storing a boolean value.
Aug 4 '10 #2
Hi insertalias,

As i'm a newbie.. will yo pls explain me with codings..
Aug 5 '10 #3
Hi kumardharanik, if you are having two radio buttons "radioButtonYes" and "radiobuttonNo", a submit button "button1" and a sql database table named "test" in your database with just one coloumn having name "checked" and data type bit. then following code can help you storing the value of checked property of radio button on button clicking.

Expand|Select|Wrap|Line Numbers
  1.          SqlConnection con = new SqlConnection("Data    Source=(local);Integrated Security=True");
  2.  
  3.          SqlCommand cmd;
  4.  
  5.          cmd = new SqlCommand("insert into test (checked) values(@check)");
  6.  
  7.          cmd.Parameters.AddWithValue("@check", radioButtonYes.Checked);
  8.  
  9.          cmd.Connection = con;
  10.  
  11.  if(con.State == ConnectionState.Closed)
  12.  {
  13.      con.Open();
  14.  }
  15.  cmd.ExecuteNonQuery();
Aug 5 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jomats | last post by:
I am a newbie trying to learn Access from several books. I'm sure this is an easy one to answer..for someone, not me. Is it possible to insert a checkbox on a form which, when checked, inserts the...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
1
Fary4u
by: Fary4u | last post by:
Hi is any body know where is actual problem is coz it's look me some problem ? to insert value into the MS ACCESS DATABASE after the value is true form html <input type="checkbox"...
7
by: mukeshrasm | last post by:
hello everyone I want to delete the selected records from database using checkbox. whch is generated dyanamically and checkbox is also generated dynamically,using php. so please help me. if you...
5
by: eihabisaac | last post by:
hi i have a field in my database (status) which have the value 0 or 1 how can i update these value using check box if checked then 1 if not checked then 0 and also how to insert values...
11
by: TechnoAtif | last post by:
INSERT AND UPDATE MULTIPLE CHECKBOX DATA USING PHPMYSQL OR JAVASCRIPT Hi All I want to check the multiple checkboxes update them after revisiting that page. I am taking the name as...
6
by: ndeeley | last post by:
Hi, How do I insert a null or blank field into a database using coldfusion? I'm new to CF and its proviing a bit tricky! My database date field accepts null values (I think - theres no default...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
1
by: puneetmca | last post by:
hi...this code of deleting a record from database using checkbox is not working...echo "<td>$row</td>; echo "<td>$row</td>"; echo "<td>$row....these lines print as it is...rather then...
2
by: digituf | last post by:
i have 2 forms here. 1) DisplayDetails.php 2) RegistrationForm.php when user click to the link 'Next' at the DisplayDetails.php page it will bring all the session value to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.