Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now