Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 11, 2010 08:44 AM by spganesh
Dec 15, 2005 04:55 PM|LINK
My Code is as follows:
When I click Edit Button the CheckBox gets the value from database and gets ticked.
But when I click Update Button, Value ' True ' gets updated to database. But when i try to update the same data the following error message appears near CheckBox:
When casting from a number, the value must be number less than infinity.
Make sure the source type is convertible to the destination type.
I want to update 1 or 2 as value for the field ACTIVE. ie the CheckBox value should be 1 or 2.
Dec 15, 2005 05:17 PM|LINK
It should be zero(0) and one (1).
0 = false
1 = true
Dec 15, 2005 05:52 PM|LINK
I would store the value in the database as type bit and then use the byte value type in your code to pass if the CheckBox is checked.
byte Checked = Convert.ToByte(chk.Checked)
Dec 16, 2005 06:20 AM|LINK
Dec 16, 2005 03:01 PM|LINK
Checked='<%# Eval("Active") %>'
I am guessing that active is a boolean field. If so when Active = 0 the check box will be unchecked and when Active = 1 the check box will be checked.
Dec 16, 2005 03:11 PM|LINK
Basically, a bit value is either 0 (True) or 1 (False). It would be ideal if the datatype for the field that stores the CheckBox values in the database to be of type bit. A condition for a checkbox is true if it is checked, and false if it is not. So, it
only makes sense to store this type of a result in a database as such.
In the code, we use the byte datatype to evaluate the CheckBox and return the appropirate value to that is compatible with the SQL bit datatype
Dim result As byte
result = Convert.ToByte(chkID.Checked)
result = Convert.ToByte(chkID.Checked);
You can then use the result from the byte conversions in your code to store a true/false value in your database.
Feb 11, 2010 08:44 AM|LINK
thanks, similar to how to get the result of same yes or no for the same condition