|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Converting SQL Server "bit" field to a CLR boolean-- has to be a better wayI'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? Jim Bancroft <asdfs***@nowhere.com> wrote:
> I'm using the DataBinder.Eval() method to output the value of a SQL Server I suggest you log what > 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? 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 - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Other interesting topics
Deadlock Problem
MSDN Exception Documentation PropertyGrid sees only public properties Killing a thread started with delegate.BeginInvoke() HTML Email DataAdapter & SQLClient Alert another session, how? Determining .NET Install Directories Embedding resource files in CLASS LIBRARY Program error cordbg.exe 0x2 |
|||||||||||||||||||||||