User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 401,534 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,391 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 3527 | Replies: 19 | Solved
Reply
Join Date: Apr 2007
Posts: 253
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

how to convert true/false to bit

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Punjab(....India....)
Posts: 31
Reputation: btech_Saurabh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

  #2  
Jan 10th, 2008
Datatype bit takes the value 0 or 1.....if true then 1
if false then 0
Reply With Quote  
Join Date: Apr 2007
Posts: 253
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #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  
Join Date: Jan 2008
Location: Punjab(....India....)
Posts: 31
Reputation: btech_Saurabh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

  #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  
Join Date: Apr 2007
Posts: 253
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #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  
Join Date: Jan 2008
Location: Punjab(....India....)
Posts: 31
Reputation: btech_Saurabh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

  #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  
Join Date: Apr 2007
Posts: 253
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #7  
Jan 10th, 2008
can u explain more clearly
Reply With Quote  
Join Date: Jan 2008
Location: Punjab(....India....)
Posts: 31
Reputation: btech_Saurabh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

  #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  
Join Date: Apr 2007
Posts: 253
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 9
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #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  
Join Date: Jan 2008
Location: Punjab(....India....)
Posts: 31
Reputation: btech_Saurabh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
btech_Saurabh's Avatar
btech_Saurabh btech_Saurabh is offline Offline
Light Poster

Re: how to convert true/false to bit

  #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 7:06 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 3:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC