Solved

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

Posted on 2009-04-07
3
435 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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