473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

save bit as 0 or 1not true or false

I have a bit field in my dataset that reads true or false, but i need to
save it to the db bit column as 0 or 1, how can i convert the true or false
to 0 or 1 so it saves into the table?
May 4 '07 #1
3 3330
GotDotNet? wrote:
I have a bit field in my dataset that reads true or false, but i need to
save it to the db bit column as 0 or 1, how can i convert the true or false
to 0 or 1 so it saves into the table?
bool bit = true; // (or false)

int zeroOrOne = (bit) ? 1 : 0;

Save zeroOrOne to the db.

HTH,
Sven
May 4 '07 #2
ACA
Hi,

i think you do not need to write a type cast for your case. if you use a
value of type boolean in your code and your db field is a bit the cast will
be done automaticly. BUT if your db field is set to nullable you have to
check DBNull first when you read the value. Or you declare your type on code
side as nullable (for example: "private boolean? myValue").

HTH
--
André Achtermeier :: Senior Consultant
www.prodot.de
"GotDotNet?" <cs*********@optonline.netwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>I have a bit field in my dataset that reads true or false, but i need to
save it to the db bit column as 0 or 1, how can i convert the true or false
to 0 or 1 so it saves into the table?

May 4 '07 #3
You shouldn't have to do anything. Just because the representation in
..NET is true and false, the provider (which I assume are the classes in the
System.Data.SqlClient namespace) will translate that appropriately to 0 and
1 on the database side (assuming you are using parameterize queries or
stored procedures).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"GotDotNet?" <cs*********@optonline.netwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>I have a bit field in my dataset that reads true or false, but i need to
save it to the db bit column as 0 or 1, how can i convert the true or false
to 0 or 1 so it saves into the table?


May 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jack | last post by:
Hi, I am trying to use the following code to make the save button invisible in the asp form when the checkbox is either on or the session variable has a particular value. THE CODE IS AS FOLLOWS:...
1
by: javzxp | last post by:
Hi I'd like to use C# to open an existing Excel workbook and save each worksheet it contains into a new Excel file. The name of each new Excel file should be the name of the worksheet copied...
0
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving...
2
by: Rubber Steve | last post by:
Can someone please tell me what is wrong with my code. The add button works fine and when I save the added record is saved but for some reason when I edit and save the information that I edited...
6
by: Ken Mylar | last post by:
I have a dilema here that I'm hoping some one can help me out with. On my forms I have some basic New, Edit, Save, Delete, Undo buttons on them. When first opened all controls on the form are not...
1
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my...
6
by: patr0805 | last post by:
Hi I am not new to vb, but I still can't solve this problem. I have flipped the image in the form, but when I save the image then the saved image is the original unflipped one) Private Sub...
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
8
by: csharpula csharp | last post by:
Hello, I am developing an application which gui is very rich with controls. My question is what is the best way to implement on c# a save require mechanism? I mean to check before closing the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.