how to convert true/false to bit

Thread Solved

Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

how to convert true/false to bit

 
0
  #1
Jan 10th, 2008
HII,
i have a column in sql srver 2000 of data type bit.I have a checkbox in my page. i want to assign bit value to the column when the check box is checked and un checked,but i am getting errors when assigning true /false to the column.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

 
0
  #2
Jan 10th, 2008
Datatype bit takes the value 0 or 1.....if true then 1
if false then 0
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: how to convert true/false to bit

 
0
  #3
Jan 10th, 2008
when iam assigning false to the coulmn iam getting error
The name 'False' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
here is my code
if (facultychecked.Checked == true)
{
anndept.announceToFaculty =true;
}
else
{
anndept.announceToFaculty =false;
}
AnnouncementManager.CreateAnnouncement(anndept);

}
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

 
0
  #4
Jan 10th, 2008
yes this is because.......it consist only true or false.....if 1 then true and if 0 then false

ur code must b like this

if (facultychecked.Checked == true)
{
anndept.announceToFaculty =1;
}
else
{
anndept.announceToFaculty =0;
}
AnnouncementManager.CreateAnnouncement(anndept);
}

if u pass 1 (or greater than 1)to ur bit datatype column....then it make is as True
if u pass 0 to ur bit datatype column in sqlserver then....it make it as false.....
Pass (1 or 0 ) value.....it automatically....insert True or False
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: how to convert true/false to bit

 
0
  #5
Jan 10th, 2008
when iam using 1 and 0 iam getting error
CS0031: Constant value '1' cannot be converted to a 'bool'
if (facultychecked.Checked == true)
{
anndept.announceToFaculty =1;
}
else
{
anndept.announceToFaculty =0;
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

 
0
  #6
Jan 10th, 2008
u can not assign 1 or 0 to a bool type variable.......
use Int type variable......and then assign 1 or 0
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: how to convert true/false to bit

 
0
  #7
Jan 10th, 2008
can u explain more clearly
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

 
0
  #8
Jan 10th, 2008
do this thing.....take one int type variable....


Int32 i;
if (facultychecked.Checked == true)
{
i =1;
}
else
{
i=0;
}

and now u have ur value in "i" ....insert the value of "i" in ur bit type column of ur table....
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: how to convert true/false to bit

 
0
  #9
Jan 10th, 2008
if (facultychecked.Checked == true)
{
k = 1;

}
else
{
k = 0;
}
anndept.announceToFaculty = k;
iam getting error
CS0029: Cannot implicitly convert type 'int' to 'bool'
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 39
Reputation: btech_Saurabh is an unknown quantity at this point 
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

 
0
  #10
Jan 10th, 2008
"anndept.announceToFaculty " this function is of bool type change this function dear.........
change this function dear........
Last edited by btech_Saurabh; Jan 10th, 2008 at 8:06 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 10927 | Replies: 19
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC