PC Review


Reply
Thread Tools Rate Thread

Converting SQL Server "bit" field to a CLR boolean-- has to be a better way

 
 
Jim Bancroft
Guest
Posts: n/a
 
      9th Feb 2005
I'm using the DataBinder.Eval() method to output the value of a SQL Server
bit field. In order to convert this value to a boolean I go through the
machination below. So far it's the only way I've been able to make this to
work; every other attempt yields an illegal-conversion or other syntax
error:

<%# Convert.ToBoolean(Convert.ToByte(DataBinder.Eval(Container.DataItem,
"myBitField"))) %>

This snippet does the job (or at least in my tests it does), but it can't be
the most efficient way to go....can it?



 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      9th Feb 2005
Jim Bancroft <(E-Mail Removed)> wrote:
> I'm using the DataBinder.Eval() method to output the value of a SQL Server
> bit field. In order to convert this value to a boolean I go through the
> machination below. So far it's the only way I've been able to make this to
> work; every other attempt yields an illegal-conversion or other syntax
> error:
>
> <%# Convert.ToBoolean(Convert.ToByte(DataBinder.Eval(Container.DataItem,
> "myBitField"))) %>
>
> This snippet does the job (or at least in my tests it does), but it can't be
> the most efficient way to go....can it?


I suggest you log what
DataBinder.Eval(Container.DataItem, "myBitField").GetType() returns -
that should let you know what's actually there, which will make it
easier to work out what to do with it.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
Reply

« A Wish..... | FTP »
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
Configure Win2K "Search" Boolean "AND" operator Clueless in Seattle Microsoft Windows 2000 1 19th Apr 2008 02:39 PM
InvalidCastException "Cast from string "6<5" to type 'Boolean is not valid. hazz Microsoft VB .NET 3 7th Jul 2005 10:22 PM
Converting Word doc. to rtf. Shows "field code change". =?Utf-8?B?c21lZGJ1?= Windows XP Help 0 1st Mar 2005 02:55 AM
<input id="iPhoto" type="file" size="20" runat="server"> Mark Sandfox Microsoft ASP .NET 1 11th May 2004 02:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 AM.