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,620 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,760 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: 3534 | 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

Re: how to convert true/false to bit

  #11  
Jan 10th, 2008
Dear if i had to change the column name ,y would i ask this question.i can not change the bool type of anncourse.announceToFaculty ,i can cast the type of k only
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

  #12  
Jan 10th, 2008
Dear.......u can not cast an integer value into a bool type variable.......u pass the value to ur Bit column according to 1 or 0...


do one thing........create a table in sql server........and insert 3 columns ("a","b" and "c") into them.....and use the Datatype Bit to all of them

Save the Table n give the name u want (like "abc")

now in Sql query analyzer..... write query for insert

insert into abc (a,b,c) values(1,0,1)

then see the result.....wat value is in ur a,b and c column

if u use this query like this insert into abc (a,b,c) values(true,false,true)
then it gives an error..........Try It Dear.........Not take much time........
Reply With Quote  
Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: how to convert true/false to bit

  #13  
Jan 15th, 2008
greeny, can you please post the code where you "built" [anndept.announceToFaculty] ?
anndept is a boolean variable, which it can only be set to true and false. When you declared anndept, you declared it as a boolean. Is anndept the column you are trying to update? In order to help you, I gotta know where you set anndept and how you set it. When updating your table, you are probably using anndept.announceToFaculty directly in the query string. You cannot do this because your database column only accepts integers, therefore true and false never get enter because they are not integers. When you set your database variable, do a simple if else statement saying:

if (anndept.announceToFaculty == true)
{
'set your query parameter = 1
} else {
'set your query parameter = 0
}

And it will update how you wish.
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

  #14  
Jan 18th, 2008
hi shesaidimapregy,
seeing u in this forum after a long time.i have created a object for announcemetBO
public struct AnnouncementBO
{
public bool announceToFaculty;
}
and called this object to my ui page
AnnouncementBO anndept = new AnnouncementBO();
if (facultychecked.Checked == true)
{
anndept.announceToFaculty = true;

}
else
{
anndept.announceToFaculty = false;

}
and iam assgining this object to the businesslogic layer.
iam getting error of invalid cast error ,can not convert bool to int
sorry that i could not reply earlier
Reply With Quote  
Join Date: Sep 2007
Location: Budapest
Posts: 251
Reputation: fatihpiristine has a little shameless behaviour in the past 
Rep Power: 0
Solved Threads: 13
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #15  
Jan 18th, 2008
no need facultychecked.Checked == true
use this. and it will work.

int k;
if (facultychecked.Checked)
{
k = 1;

}
else
{
k = 0;
}
Reply With Quote  
Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: how to convert true/false to bit

  #16  
Jan 18th, 2008
the reason why you cannot set anndept.announceToFaculty to an integer (1 or 0) is because you declared it as a boolean [public bool announceToFaculty]. You can change it to an integer by setting the above declaration to "public int announceToFaculty] and you will be able to set it to (1 or 0). If it is required for you to have announceToFaculty as a boolean, create a second variable and make it an integer. This isn't needed as you can set any value within a parameter at the end of the struct anyway:
if (anndept.announceToFaculty.Checked) {
    'set parameter equal to 1
} else {
    'set parameter equal to 0
}
And you do not need to say:
if (facultychecked.Checked == true)
any checkbox referred to in code is defaulted to true. so saying "if (facultychecked.Checked)" is the same as saying "if (facultychecked.Checked == true)". It's just better programming, but not anything bad.

Originally Posted by greeny_1984 View Post
hi shesaidimapregy,
seeing u in this forum after a long time.i have created a object for announcemetBO
public struct AnnouncementBO
{
public bool announceToFaculty;
}
and called this object to my ui page
AnnouncementBO anndept = new AnnouncementBO();
if (facultychecked.Checked == true)
{
anndept.announceToFaculty = true;

}
else
{
anndept.announceToFaculty = false;

}
and iam assgining this object to the businesslogic layer.
iam getting error of invalid cast error ,can not convert bool to int
sorry that i could not reply earlier
Last edited by SheSaidImaPregy : Jan 18th, 2008 at 9:12 am.
Reply With Quote  
Join Date: Dec 2007
Posts: 287
Reputation: ericstenson is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: how to convert true/false to bit

  #17  
Jan 18th, 2008
wow. that's a long thread for a simple problem.
--
"Dummy."
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

  #18  
Jan 19th, 2008
hi ,
i will explain u my problem clearly
AnnouncementBO anndept = new AnnouncementBO();
anndept.announcement = txtdescription.Text;
anndept.announcementDate = DateTime.Parse(txtanndate.Text, new CultureInfo("fr-FR"));
anndept.category = int.Parse(ddlcategory.SelectedItem.Value);
anndept.deptID = -1;
if (facultychecked.Checked )
{

anndept.announceToFaculty=true;
}
else
{

anndept.announceToFaculty =false;
}
AnnouncementManager.CreateAnnouncement(anndept);
this is my code for a click event
i have a business logic layer called announcementmanager in which we send the object anndept.anndept is a entity object
public struct AnnouncementEO
{

public int deptID;
public int courseID;
public int batchID;
public string announcement;
public int category;
public DateTime announcementDate;
public bool announceToFaculty;
}
i can not change the data type of announcetofaculty nor can i use another parameter.i should use only announceToFaculty.
but when i assign true /false to it iam getting error
The name 'False' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
when iam using 1/0 to anndept.announceToFaculty iam getting error
CS0031: Constant value '1' cannot be converted to a 'bool'
the column in the data base for announcetofaculty is declared bit
Reply With Quote  
Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: how to convert true/false to bit

  #19  
Jan 19th, 2008
Sir, you have this right here:

public bool announceToFaculty;


Which means you can only assign true or false to it. If you are not allowed, change this part to:

public int announceToFaculty;

And assign 1/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

  #20  
Jan 21st, 2008
The problem is solved ,i have converted announceToFaculty to int in ui page
and assigned that in businesslogic layer as follows
annEO.announceToFaculty = ann.announceToFaculty?1:0;
and this works perfectly.
thanks to every one who have replied
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 5:37 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC