Solved

saving C# windows form checkbox value of 1 or zero into a sql server or oracle table

Posted on 2009-04-07
3
424 Views
Last Modified: 2012-05-06
I have a basic checkbox in a C# windows form. Lets say the form is called   Form1.cs

In my form I brought in the checkbox controls for 3 checkboxes.

I have created a column in my database table for each check box value.

So if the check box is checked the value that will go in the column will be 1
if the value in the checkbox is not checked the value in the column for that checkbox remains 0.

Whats the easiest cleanest way to set up this form?

say i have 3 checkboxes that are called the following

checkbox1
checkbox2
checkbox3

My database is a SQL server database.

The table is called CheckboxDB
The columns in this db are:

checkbox1value
checkbox2value
checkbox2value
0
Comment
Question by:maq10
3 Comments
 
LVL 7

Accepted Solution

by:
DanSo1 earned 63 total points
ID: 24091110
125 points is not enough but I will try my best.
1. Add to your project DataSet, then create TableAdapter on it (it's easy).
2. On your form choose option from menu -> Data -> Show Data Sources, choose just one field from your dataset - table. You should see below your form some components like DataSet,BindingSource,TableAdapter and more
3. Use in your checkbox property DataBindings - Checked. Choose proper field thrue your dataset.
4. Delete from your form what is not neccesary (for example editbox, bindingNavigator etc).
5.You can save changes to DB by calling:
this.Validate();
this.tblMyTableMailBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dstMyDataSet);
those lines you can put in event for example ButtonClick.
Regards
  Danso
0
 
LVL 26

Assisted Solution

by:Anurag Thakur
Anurag Thakur earned 62 total points
ID: 24093915
i am not giving you a complete solution but giving you a pointer how to achieve the functionality you need
http://www.dotnetspider.com/forum/197712-How-store-checkbox-value-sql-database-if-checked-using-c.aspx.aspx

-- in summary what you can do is if the check box is checked you can pass 1 or else 0 to the database stored procedure or C# query and when you fetch the values in the select from the database you can just convert that to boolean and assign to the check box.checked property
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now