Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hello ,
I am retrieving bit value from database and sending it to a table using service. problem is that c# dosen't have bit type. so i have to either retrieve it as boolean or int.

And this is affecting the result table to which i am binding the data.

bit will be shown as checkbox where as Boolean is shown as true false in table. i want to show as checkbox. table is client side and is being bind using javascript ajax call.
Posted
Comments
Debojyoti Saha 28-Oct-15 2:41am    
Can you try
Convert.ToBoolean(bitvalue);
Riya-Pandey 28-Oct-15 2:43am    
i am retrieving the value as boolean. in this case table is showing true / false. but i want to show checkbox [checked / uncecked] which is only possible in case of it value.
phil.o 28-Oct-15 2:55am    
You just counfound a valuetype (the boolean) with one of the way to display and edit it (the checkbox); these are not the same.
[no name] 28-Oct-15 2:44am    
Can you explain little bit more ? Are you binding checkbox on the basis of bit value ?
Riya-Pandey 28-Oct-15 3:22am    
i am binding to a table. table only has header
<table id="datatable">
<thead>
<tr>
<td>
ID
</td>
<td>
Description
</td>
<td>
Deleted
</td>
</tr>
</thead>
</table>

Now if i bind it directly then it shows checkbox but if i bind it using json for that i have to serialize the the list of client and when adding data to client i have to convert it to boolean. so it's showing true false under delete column where as i want checkbox

1 solution

It sounds like you act in a wrong believe that you really store "bit values" in your database. I would like to see it. In reality, "bit types" are not used per se, they would probably pretty useless. But Boolean values, logically requiring 1 bit, can be packed in structures where they really take one bit, which only makes sense if you have a bulk of such values.

In .NET, look at this type: https://msdn.microsoft.com/en-us/library/system.collections.bitarray%28v=vs.110%29.aspx[^].

Also, you need to know how bits are accessed. Please see: https://msdn.microsoft.com/en-us/library/6a71f45d.aspx[^].

This CodeProject article can also be helpful: Understand how bitwise operators work (C# and VB.NET examples)[^].

I'm not saying it will help you to solve your present problem directly. It's just something useful to understand. But it should help you to overcome your misconception. If you need further help, please clarify.

—SA
 
Share this answer
 
v2
Comments
Riya-Pandey 28-Oct-15 3:25am    
I read the Articles that you provided . although it was not helpful for the current problem yet gaining some insight as to how things work is always helpful. Thank you
Sergey Alexandrovich Kryukov 28-Oct-15 9:51am    
I already mentioned it. Nothing can help you. It will be helpful if you dismiss you misconception. There is no a problem you need help with.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900