?
Solved

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

Posted on 2009-04-07
3
Medium Priority
?
493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
DanSo1 earned 252 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 248 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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