 |
| 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 24th, 2006, 10:22 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Retrieve value and Mark Checkbox
Per a previous question I was able to save the value of Checkbox into a database using the following code:
int i;
if(humanSubject.Checked)
{
i = 1;
}
else
{
i = 0;
}
f1.HUMANSUBJECT = i.ToString();
Now I need to retrieve the value of 1 or 0 and recheck the Checkbox on a separate form. I typed the code to do so like this:
string i = f1.HUMANSUBJECT;
if(i = 1)
{
this.humanSubject.Checked = true;
}
else
{
this.humanSubject.Checked = false;
}
However the following piece 'if(i = 1)' generates two errors, one saying one saying a string cannot be converted to bool and that the 1 is an int that cannot be converted to a string. I tried changing 'i' to a bool but received another error about bool to string conversion. I also tried not to use the string value and do a more direct 'if(f1.HUMANSUBJECT = 1)' but received a cannot convert string to int. What is the correct way to convert this?
rdove84
|
|

October 24th, 2006, 10:24 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Do this:
if(i == 1){}
else{}
= sets values == checks equality
-------------------------
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, 10:26 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Err, wait. Thats incorrect. You want to do if(i == "1"){} else{} I just realized you were creating i as a string.
-------------------------
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, 11:01 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you again for your assistance.
The code compiles without error, however, when I login into the form I get the following error:
Specified cast is not valid.
Line 145: this.continuation = tempDR.IsDBNull(33) == true ? "" : tempDR.GetString(33);
Line 146: this.humanSubject = tempDR.IsDBNull(34) == true ? "" : tempDR.GetString(34);
Line 147: this.numberAnimals = tempDR.IsDBNull(35) == true ? "" : tempDR.GetString(35);
Do I need to change the GetString to Get an Integer instead and will that mess up the original code that saves the value as a string?
rdove84
|
|

October 24th, 2006, 11:23 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ah, good news. I fixed the problem which actually resided in my design table. Thanks so much for all of your help.
rdove84
|
|

October 24th, 2006, 12:23 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
No problem, glad you got it fixed.
-------------------------
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
|
|
 |