|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
October 23rd, 2006, 03:34 PM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Save Checkbox with boolean 0/1 value
I have several checkboxes on a web form whose values I need to save to a database, then be able to retrieve them to an editable form. I know that to retrieve them, I need the check box to save not as the usual true/false answer but as a tinyint 1 or 0 in a SQL database table.
Is there C# code available to help me figure this out?
rdove84
|
October 23rd, 2006, 04:23 PM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Just create a variable
int i;
if(checkbox.checked){
i = 1;
}
else{
i = 0;
}
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
October 24th, 2006, 08:45 AM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for such a quick reply.
I have one more question. I'm saving my information via a stored procedure into a column marked tinyint. All of my other columns from my form are saved via lines like this:
f1.ELECTRICITY = this.electricity.SelectedValue; (or Text, etc)
However, when I try to save the Checkbox items I get one of two messages. The item cannot be implicitly converted from string to int or cannot implicitly convert bool. I thought at first after the making my checkbox equal 1 or 0 that I then should call a line like the one above (f1.HUMANSUBJECT = this.humanSubject.Checked) but I keep getting errors. Is there something else I should be doing?
rdove84
|
October 24th, 2006, 08:54 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
ok you can't do f1.HUMANSUBJECT = this.humanSubject.Checked if you have declared f1.HUMANSUBJECT as an integer because the return type of this.humanSubject.Checked is a boolean. I see 2 choices:
1)Change your database datatable column from tinyint to a BIT datatype and you can pass in a bool value (TRUE/FALSE)
2)You will have to use an If statement to determine what the value of your int will be.
hth
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
October 24th, 2006, 09:11 AM
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you so much that did the trick.
|
October 24th, 2006, 09:12 AM
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
No problem glad it worked. =]
-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
^^Thats my signature
|
|
|