Wrox Programmer Forums
|
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
 
Old October 23rd, 2006, 03:34 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default 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

 
Old October 23rd, 2006, 04:23 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old October 24th, 2006, 08:45 AM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

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

 
Old October 24th, 2006, 08:54 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old October 24th, 2006, 09:11 AM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

Thank you so much that did the trick.



 
Old October 24th, 2006, 09:12 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save checkbox settings to cookie clockwork Beginning PHP 1 November 20th, 2007 05:45 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
boolean starlightt Java Basics 2 April 6th, 2006 05:34 PM
How to i save checkbox value to database ADO guanxian VB Components 1 December 13th, 2005 06:19 PM
How do I send boolean values with a checkbox babou SQL Server ASP 2 March 28th, 2005 05:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.