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 24th, 2006, 10:22 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 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

 
Old October 24th, 2006, 10:24 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

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
 
Old October 24th, 2006, 10:26 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

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
 
Old October 24th, 2006, 11:01 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 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

 
Old October 24th, 2006, 11:23 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

Ah, good news. I fixed the problem which actually resided in my design table. Thanks so much for all of your help.

rdove84

 
Old October 24th, 2006, 12: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

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrieve checkbox values which are checked SMM Classic ASP Professional 2 June 3rd, 2007 06:45 PM
Insert statement with Quatation mark maz_alaameri ASP.NET 2.0 Professional 3 April 19th, 2007 01:42 PM
Mark change in a table stealthdevil Access VBA 3 October 23rd, 2006 10:40 AM
str_replace for quotation mark starsol Beginning PHP 4 August 21st, 2003 11:25 AM





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