Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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