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

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

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

    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(C ontainer.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 Guest

  2. Similar Questions and Discussions

    1. "Page" and "Rect" props of the Field prop in Javascript API
      Page property of the Field property in Javascript Acrobat API returns an array of pages that this field exists in. On the other hand, "rect" property...
    2. #39904 [NEW]: string -> boolean conversion of "\0" could give FALSE
      From: zizka at seznam dot cz Operating system: PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: ...
    3. Compare 2 fields & delete everything in "field 2" that occurs in "field 1"
      Is it possible to compare 2 fields and delete everything in "field 2" that also occurs in "field 1" ? FIELD1 800-555-1212 for...
    4. Request.Form("Field Name") Versus Request.QueryString("Field Name")
      I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the...
    5. dr("field").toString returns "400.0000" instead of "400"
      I have just installed VS.NET 2003 on my computer. I have a project that I have been developing on VS.NET 2002. I haven't upgraded this project to...
  3. #2

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

    Jim Bancroft <asdfsklw@nowhere.com> 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(C ontainer.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 - <skeet@pobox.com>
    [url]http://www.pobox.com/~skeet[/url]
    If replying to the group, please do not mail me too
    Jon Skeet [C# MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139